给定一个存储 li
元素的对象,我想找到它们的 ID:
$($selected).each(function(){
console.log($selected.attr('id'));
$(this).fadeOut(function(){
$(this).appendTo($list).removeClass("ui-state-highlight").fadeIn();
});
});
}
这只是给我第一个。为什么?
最佳答案
那是因为您在 $selected
对象上调用 attr
方法,而 attr
仅返回 jQuery 集合中第一个选定元素的 ID,您应该在 each
回调中使用 this.id
或 $(this).prop('id')
。
$selected.each(function(index, element) {
console.log(this.id);
// ...
})
关于javascript - 对象不会给出元素的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16390079/