http://jsfiddle.net/PhilFromHeck/KzSxT/的Javascript比較對象元素
在這個小提琴,你可以在Javascript代碼行38,我曾經嘗試不工作的比較看。我相信這是因爲其中一個變量是一個Object,另一個是Element;有沒有人有任何建議,我怎麼能找到這兩者之間的匹配?
menuID[0] = document.getElementById('menuOne');
menuID[1] = document.getElementById('menuTwo');
menuID[2] = document.getElementById('menuThree');
menuID[3] = document.getElementById('menuFour');
$('.menu').mouseenter(function() {
for (var i = 0; i < 3; i++) {
if(menuID[i] == $(this)){
//this condition is not met, there's an alert which will add more detail in the fiddle
}
}
}
減少jQuery,不是更多的更好的答案在這裏。是;這會起作用,但是當你想要的只是對象本身時,你基本上是打包並解開對象。 – Retsam
@ Retsam:是的,我意識到了。無論如何,我會在這裏留下。 –