Jquery 刷新类中的所有div
如何根据它们的类名刷新所有div? 我这么做了,但没用Jquery 刷新类中的所有div,jquery,ajax,reload,Jquery,Ajax,Reload,如何根据它们的类名刷新所有div? 我这么做了,但没用 setInterval(function() { $('.myclass').each(function () { $(this.id).load(location.href+" this.id>*",""); }); }, 10000); $(this.id).load(…在不使用#前缀的情况下创建一个无效选择器,但您真正需要的是$(this).load(…),因为您已经有了对该元
setInterval(function()
{
$('.myclass').each(function () {
$(this.id).load(location.href+" this.id>*","");
});
}, 10000);
$(this.id).load(…
在不使用#
前缀的情况下创建一个无效选择器,但您真正需要的是$(this).load(…
),因为您已经有了对该元素的引用
然后,将id添加到url的末尾也会出现语法错误
您最好只发出一个请求,然后自己解析响应。这比对完全相同的资源发出多个请求更有效
setInterval(function(){
$.get(location.href, function(data){
// loop through the new elements
$(data).find('.myclass').each(function(){
const id = this.id,
content = $(this).html();
// insert into existing element with same id
$('#' + id).html(content);
});
});
},10000)
“刷新”到底是什么意思?你想实现什么?这是动态数据,我想每隔10秒从服务器重新加载数据