2016-04-28 76 views
0

我有一個表在我的HTML代碼,我把一類的<li>標籤「彈出」窗口,如下圖所示:鏈接打開不同的內容

<li class="modal-trigger"><img src="http://apolosiskos.co.uk/images/movies/21grams.jpg">21 Grams</li> 
<li class="modal-trigger"><img src="http://apolosiskos.co.uk/images/movies/amoresperros.jpg">Amores Perros</li> 
<li class="modal-trigger"><img src="http://apolosiskos.co.uk/images/movies/babamveoglum.jpg">Babam Ve Oglum</li> 

當有人點擊該鏈接後,彈出應該顯示出來。我想讓彈出的內容獨一無二。如果有人點擊第一個,應該會彈出關於21grams電影的信息。如果有人點擊第二個,對於愛情是狗娘等:

<div id="ModalContentWrap" class="modal-wrap"> 
    <div class="modal-content mix"> 
    <section id="stigma-box"> 
     <header> 
     <h1>21 Grams</h1> 
     <span class="avatar"><img src="http://apolosiskos.co.uk/images/movies/21grams.jpg" alt="" /></span> 
     <h3><a href="http://www.imdb.com/title/tt0315733/" target="blank">A freak accident brings together a critically ill mathematician, a grieving mother, and a born-again ex-con.</a></h3> 
     </header> 
    </section> 
    </div> 
</div> 

<div id="ModalContentWrap" class="modal-wrap"> 
    <div class="modal-content mix"> 
    <section id="stigma-box"> 
     <header> 
     <h1>Amores Perros</h1> 
     <span class="avatar"><img src="http://apolosiskos.co.uk/images/movies/amoresperros.jpg" alt="" /></span> 
     <h3><a href="http://www.imdb.com/title/tt0245712/" target="blank">A freak accident brings together a critically ill mathematician, a grieving mother, and a born-again ex-con.</a></h3> 
     </header> 
    </section> 
    </div> 
</div> 

<div id="ModalContentWrap" class="modal-wrap"> 
    <div class="modal-content mix"> 
    <section id="stigma-box"> 
     <header> 
     <h1>Father and Son</h1> 
     <span class="avatar"><img src="http://apolosiskos.co.uk/images/movies/babamveoglum.jpg" alt="" /></span> 
     <h3><a href="http://www.imdb.com/title/tt0476735/" target="blank">Sadik is one of the rebellious youth who has been politically active as a university student and became a left-wing journalist in the 70's, despite his father's expectations of him becoming...</a></h3> 
     </header> 
    </section> 
    </div> 
</div> 

通過上面這段代碼,不管我點擊,我得到一個彈出一個帶有唯一的第一部電影的信息。

回答

0

請注意,您的所有模式ID都相同,因此您需要將它們更改爲唯一。您需要將每個觸發器設置爲獨特。

例如(這只是用一個模式不能使用代碼的方式爲例):

<a href="#test1" data-toggle="modal">Click me for test1 id!</a> 
<div id="test1" data-type="modal"> 
    Some content here... 
</div> 


我建議你,如果你使用的是看看http://www.w3schools.com/bootstrap/bootstrap_modal.asp Bootstrap ...

+0

我該如何動態更改:id =「ModalContentWrap」。它必須是id =「ModalContentWrap_1」和id =「ModalContentWrap_2」等每個框。但是,這將使css文件變大。 –

+0

這是正確的。這就是爲什麼你應該使用模板模式,然後使用Ajax加載內容! –

+0

任何方式來做到這一點?在stackoverflow上的任何用例可能?我以前從未使用過AJAX。 –