当我执行以下代码时,我希望相同的元素 id 会被警告两次,但相反,第一个是正确的,而第二个总是显示集合中第一个元素的名称。
$("div.someClass").each(function (index) {
$(this).click(function () {
alert($(this).attr("id")); // Here i get the actually clicked element
$.when($("div.someClass").animate({ }, 0)).then(function () {
alert($(this).attr("id")); // Here i get the first element in of that class
});
});
});
为什么会这样?如何解决?我尝试将元素的名称传递给函数,但它不起作用。