0
我能夠使用JSfiddle創建一個appendTo事件。通過點擊圖片,我可以獲得打印在另一個div列表中的圖像的標題。但是,如果我想將它附加到另一個頁面中,該怎麼辦?appendTo另一個頁面上的表單?
另外,如何刪除一個項目後添加它?我目前有的代碼允許我appendTo,但我不知道如何撤銷這個事件...有什麼建議嗎?
這裏是JS提琴:http://jsfiddle.net/jhyqt5/cBsqN/20/
和守則:
HTML
<div class="wrapper">
<div class="caption">Blueberry</div>
<img src="https://scontent-a-pao.xx.fbcdn.net/hphotos-prn2/1394351_529524313783586_609777864_n.jpg" class="img-circle">
</div>
<div class="wrapper">
<div class="caption">Walnuts</div>
<img src="https://scontent-b-pao.xx.fbcdn.net/hphotos-ash4/1377244_529524413783576_249384396_n.jpg" class="img-circle">
</div>
<div class="wrapper">
<div class="caption">Craisins</div>
<img src="https://scontent-b-pao.xx.fbcdn.net/hphotos-frc3/1378714_529524353783582_129148654_n.jpg" class="img-circle">
</div>
<br>
<br>
<div class="foodlist">
</div>
CSS
.img-circle {
border-radius: 50%;
height: 140px;
width: 140px;
}
.wrapper {
position: relative;
}
.caption {
background-color: black;
opacity: .7;
text-align: center;
line-height: 120px;
color: white;
position: absolute;
display: none;
border-radius: 50%;
width: 140px;
height: 140px;
}
.wrapper:hover .caption {
display: block;
}
.wrapper.active .caption {
display: block;
opacity: .8;
background: #38ACD5;
}
JS
$('.wrapper').on('click', function() {
$(this).toggleClass('active');
var caption = $(this).find(".caption").text();
$("<li>" + caption + "</li>").appendTo("div.foodlist");
});
底線:
1)appendTo和撤銷功能 2)appendTo形式的另一頁上
謝謝:)
您可以使用數組作爲中間步驟。將項目添加/刪除到陣列並使用'.html'寫入整個數組。對於#2,你可以在頁面之間傳遞數據 - 取決於你的語言:php,asp? – greener
當你說「附加到另一頁到表單」時,你究竟是什麼意思?你的意思是不同的瀏覽器頁面?如果是這樣,該瀏覽器頁面是否加載到另一個窗口?或者將來會加載一些時間? – jfriend00
您可以使用$。('#id')。slideUp(0);立即隱藏一個div,但空間也會「打開」。我不知道你的意思是追加到「另一個頁面」 - 如果你的意思是一個完全獨立的選項卡,沒有發佈到新的頁面本身......如果可能的話,這是idk。 –