Html 使用JQuery将块作为最后一个子项插入选定标记中
我正在开发一个评论模块,每5秒自动刷新一次。代码如下所示: jQuery部分:Html 使用JQuery将块作为最后一个子项插入选定标记中,html,jquery,Html,Jquery,我正在开发一个评论模块,每5秒自动刷新一次。代码如下所示: 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
$(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);
});
<div id="abc"></div>
$(文档).ready(函数(){
var refreshId=setInterval(函数(){
$.getJSON('process.php?fooId=1',函数(数据){
$。每个(数据、函数(键、值){
$('abc:last child')。前置('some text');
});
});
}, 5000);
});
HTML部分:
$(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);
});
<div id="abc"></div>
我需要的是,当有人评论时,评论必须附加到div中(id=“abc”
)
有解决方案吗?使用insertAfter()
官方文件:
$('some text')。插入后面($('abc:last child');
试试这个:
$(document).ready(function(){
var refreshId = setInterval(function(){
$.getJSON('process.php?fooId=1', function(data){
$.each(data, function(key,val){
$('#abc').last().append(val);
});
});
}, 5000);
});
这对我来说是行不通的,因为我想要的是;“val”必须位于like的内部:“val”如果使用insertAfter,它会将“val”放在这个div之后,看起来像:“val”我已经使用了两个$(“#abc”).last().append(val);和$('abc:last child')。追加(val);但是没有用(还有,您是如何发送注释的。$.getJSON('process.php?fooId=1,comment=enteredcoment'this
comment=enteredcoment
应该是这样的:{“comment”:enteredcoment}
好的,但这不是问题,我在处理后会得到所有必需的值。我需要的是将所有数据附加到这个父div中(id='abc')但它根本不起作用!