jQuery回调函数需要使用.each替换参数 [英] jQuery callback function needs to replace parameter using .each
本文介绍了jQuery回调函数需要使用.each替换参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要使用这个函数,它将在具有某个类的页面中使用.each循环遍历所有DIV,然后将DIV替换为.get的结果。这是代码:
$(function(){
window.setInterval(function(){
$( 。cstat)。each(function(i){
$ .get( getcustomerstatus.asp?customerid = + this.id).done(function(data){$( # + this.id).html(data);});
})
},10000);
})
问题是.done中的this.id我认为在从.get返回数据时进行评估。我的目标是更换所有DIV。所以我的整体问题是有一种方法可以使.done部分的this.id在.get而不是.done时插入吗?
谢谢
解决方案
(function(){
window.setInterval(function(){
(< span class =code-string> .cstat)。each(function(i){
.get( getcustomerstatus.asp?customerid = + this.id).done(function(数据){
I have this function I want to use that will cycle through all the DIVs using .each in a page that have a certain class, then the DIV get replaced by the results of a .get. Here is the code:
$(function(){
window.setInterval(function() {
$(".cstat").each(function (i) {
$.get("getcustomerstatus.asp?customerid="+this.id).done(function(data){$("#"+this.id).html(data);});
})
}, 10000);
})
The problem is that in the .done the "this.id" I believe gets evaluated at the return of the data from the .get. My goal is to replace all the DIV. So my overall question is there a way to make the this.id in the .done section get "inserted" at the time of the .get instead of the .done?
Thanks
解决方案
(function(){ window.setInterval(function() {
(".cstat").each(function (i) {
.get("getcustomerstatus.asp?customerid="+this.id).done(function(data){
这篇关于jQuery回调函数需要使用.each替换参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文