2013-02-26 18 views
0

我正在對每5秒自動刷新一次的評論模塊進行操作。該代碼是這樣的:使用JQuery將塊作爲最後一個孩子插入選定標記內

jQuery的部分:

$(document).ready(function(){ 
var refreshId = setInterval(function(){ 
$.getJSON('process.php?fooId=1', function(data){ 
    $.each(data, function(key,val){ 
     $('#abc:last-child').prepend('<div>some text</div>'); 
    }); 
    }); 
}, 5000); 
}); 

HTML部分:

<div id="abc"></div> 

我需要的是,當有人評論,註釋必須附加到DIV (id="abc")。

任何解決方案?

回答

0

使用insertAfter()

官方文檔http://api.jquery.com/insertAfter/

$('<div>some text</div>').insertAfter($('#abc:last-child')); 
+0

,因爲我要的是它不會在我的情況下工作;在「VAL」必須是內等:

'val'
如果使用insertAfter,它將會把「VAL」這個div後,看起來像:
「VAL」 – 2013-02-26 06:24:02

0

試試這個:

$(document).ready(function(){ 
    var refreshId = setInterval(function(){ 
    $.getJSON('process.php?fooId=1', function(data){ 
     $.each(data, function(key,val){ 
      $('#abc').last().append(val); 
     }); 
    }); 
    }, 5000); 
}); 
+0

我都用了$(「#ABC」)最後() .append(VAL);和$('#abc:last-child')。append(val);但沒用。 :( – 2013-02-26 06:24:54

+0

是你得到'數據'在JSON格式。 – Jai 2013-02-26 06:29:25

+0

也你怎麼發送評論。 – Jai 2013-02-26 06:30:59

相關問題