jQuery:正在尝试运行$.get in.each函数
这段代码确实获得了带有“profileName”类的每个元素的索引值。它还使用每个索引值作为url运行$.get。但是,当我试图将ajax响应放入每个元素时,它失败了,每个元素都有“details”类,它是每个“profilName”div的子元素。这可行吗jQuery:正在尝试运行$.get in.each函数,jquery,Jquery,这段代码确实获得了带有“profileName”类的每个元素的索引值。它还使用每个索引值作为url运行$.get。但是,当我试图将ajax响应放入每个元素时,它失败了,每个元素都有“details”类,它是每个“profilName”div的子元素。这可行吗 $('.profileName').each(function(index) { var urlVal = $(".showProfile", this).attr('profile'); $.get(urlVal, fun
$('.profileName').each(function(index) {
var urlVal = $(".showProfile", this).attr('profile');
$.get(urlVal, function(data) {
$(".details", this).html(data);
}, "html");
});
这是因为
此
不涉及成功
回调中所需的内容。您可以通过提前存储来修复它,如下所示:
$('.profileName').each(function(index) {
var urlVal = $(".showProfile", this).attr('profile'),
details = $(".details", this);
$.get(urlVal, function(data) {
details.html(data);
}, "html" );
});
在下面使用,和。这是因为
此
不涉及成功
回调中所需的内容。您可以通过提前存储来修复它,如下所示:
$('.profileName').each(function(index) {
var urlVal = $(".showProfile", this).attr('profile'),
details = $(".details", this);
$.get(urlVal, function(data) {
details.html(data);
}, "html" );
});
使用下面,和