[code=html
<select>
<option>列表1</option>
<option>列表2</option>
<option>列表3</option>
<option>列表4</option>
<option>列表5</option>
</select>
[/code]
采用jqueryvar $select1=$("select");
var $select2=$("select");
alert($select1==$select2);//false
alert($select1[0]==$select2[0]);//true
为什么jquery对象不相等,dom对象相等?求大神帮忙jquery dom 对象 相等jquerydom对象相等,
<select>
<option>列表1</option>
<option>列表2</option>
<option>列表3</option>
<option>列表4</option>
<option>列表5</option>
</select>
[/code]
采用jqueryvar $select1=$("select");
var $select2=$("select");
alert($select1==$select2);//false
alert($select1[0]==$select2[0]);//true
为什么jquery对象不相等,dom对象相等?求大神帮忙jquery dom 对象 相等jquerydom对象相等,
}
var $a = new EqOrN();
var $b = new EqOrN();
var $c = ($a==$b);
var $select1=$("select");//返回的是数组[]
var $select2=$("select");//返回的是数组[]
alert($select1==$select2);//[]==[]数组返回false
alert($select1[0]==$select2[0]);//数组的第一个对象都是指向同一个引用对象
它只是把html的dom对象包到jq对象里了 不是直接在dom上增加的
var p2=document.getElementsByTagName("select");
alert(p1==p2);//true p1、p2是数组
function EqOrN(){
}
var $a = new EqOrN();
var $b = new EqOrN();
var $c = ($a==$b);
a = new EqOrN();
function gE(){
return a;
}
var $d = gE();
var $e = gE();
var $f = ($d == $e);
var $g = new gE();
var $h = new gE();
var $i = ($g==$h);
var p2=document.getElementsByTagName("select");
alert(p1==p2);//true p1、p2是数组
你这里取到的p1 p2虽然有length的属性,但并非数组,而是一个类数组的东西,dom中称作NodeList。你可以用数组的push,pop等方法检测一下。至于用jquery取,取出来的是两个对象,只不过是有一样的属性和方法而已。
比如说一对一模一样的双胞胎(A和B),你能说A就是B,B就是A吗~~
console.log($select2);