我将一些元素保存到一个数组中以便以后能够确定我点击了哪一个,但我的方法不起作用。 (稍后,我将使用数组索引来计算一些东西)。以下if语句永远不会变为“true”。怎么了? HALP!
$(document).ready(function() {
var teamList = [];
$('#team-list').children(".team-member").each(function() {
teamList.push($(this));
});
$('#team-list').on("click", ".team-member", function() {
console.log("click");
for (i = 0; i < teamList.length; i++) {
console.log("The element was");
console.log($(this));
console.log("and the loop is on");
console.log(teamList[i]);
if ($(this) == teamList[i]) {
console.log("it was true");
}
};
});
});
答案 0 :(得分:0)