我需要将一个元素传递给一个函数,然后在遍历父项时匹配该特定元素。捕捉(对于像我这样不懂的人)是因为这个元素没有id。在下面的例子中,我希望每一个元素变成粉红色,除了一个点击应该变黄jQuery - 如何检查两个元素是否相同?
function colorize(element) {
element.parent().find('span').each(function() {
if ($(this)===element) { // the problem is this is always false
$(this).css('background','yellow');
} else {
$(this).css('background','pink');
}
});
}
$('span').click(function() {
colorize($(this));
});
见http://stackoverflow.com/questions/4441135/how-to-compare-two-doms-or-dom-nodes-in-general –