我正在顯示一個提示div,我也想在提示div的末尾顯示'updated at'消息。我正在嘗試這種方式:爲什麼InsertAfter在這種情況下不起作用
var sampledata = [{
"name": "John",
"tip": "BUY 111",
"time": "23-DEC"
},{
"name": "John",
"tip": "BUY 232",
"time": "23-DEC"
}]
$(function() {
$(".cl").html(""); // Clearing the HTML
for (var i = 0; i < sampledata.length; i++) {
var name = sampledata[i].name;
var tip = sampledata[i].tip;
var time = sampledata[i].time;
var html = '';
html += '<a href="#" class="c1">\
<div class="stoc5 mt1">\
<div class="c1 fl wi80">\
<span class="fl c2 f14 ti-s mt">' + time + '</span>\
' + tip + '\
</div>\
<div class="fr c2 f14 ti-s1 mt"></div>\
<div class="cl"></div>\
</div>\
</a>';
$(".cl").append(html);
}
var newhtml = '<div class="updated_attipes">23-DEC-2015</div>';
$(".cl").insertAfter(newhtml);
});
請你讓我知道如何顯示更新後的div div技巧? https://jsfiddle.net/pL7xugg1/28/
但爲什麼消息顯示多次 – Pawan
這是因爲你在循環中追加了多個'.cl'元素。刪除該元素來阻止該行爲:https://jsfiddle.net/pL7xugg1/32/ –
非常感謝... – Pawan