2013-11-22 34 views
0

的後續行動,我已經張貼在這個線程:第2部分:JQuery的加入隱藏的HTML元素

JQuery Add Hidden HTML Elements

<input type='button' value='Show Picture' id='add'> 
<div class='input'style='display: none;'> 
<div class="form" id="inter"></div> 

這是我的作品。當我按下按鈕時,圖像出現。

$("#add").click(function() { 
    $(".input:hidden:first").toggle() 
}); 

我的JQuery的另一部分,當我按下它消除了股利。 (正如我本來打算這麼做的)。

問題是,當我再次按下按鈕時,圖像不再重現。 我希望它像無盡的循環一樣工作。我顯示圖像,點擊它關閉它,點擊按鈕,圖像再次顯示。

+0

這是你想要的嗎? http://jsfiddle.net/7KGEu/ – PSL

回答

0

我相信與你的第一個答案非常相似的東西應該可以工作。請試試這個:

$("#add").click(function() { 
    $(".form").toggle(); 
}); 
+0

我的每個div都有一個類和一個id,(例如:div class =「form」id =「inter」)你做的是我想要的,但我也需要ID。我怎麼能這樣做? @Frog我試過,但它似乎沒有工作。也許是因爲我忘了提到這個ID? 對不便。 – tinthetub

0

我認爲你每次點擊按鈕時都會附加div,你所做的就是替換div的內容。

<input type='button' value='Show Picture' id='add'> 
<div class='input'> 
    <div class="form" style="display:none;">Somgthing here</div> 
</div> 
<div id="container"></div> 

<script> 
$("#add").click(function() { 
    $('#container').html($('.input').html()).find('.form').show(); 
}); 
</script> 

http://jsfiddle.net/Jp4pq/16/

檢查。