jQuery的get和eq的区别

来源:互联网 发布:美国mobi域名2017年 编辑:程序博客网 时间:2024/06/02 07:30

<p>This just a test. </p>

<p>So is this </p>

<a href="#" id="test" onClick="jq()">jQuery</a>

 

function jq(){

alert($("p").get(1).innerHTML);//弹出So is this ..  下标从0开始

}

 

function jq(){

alert($("p").eq(1).html());//弹出So is this

}

 

get和eq的区别,eq返回的是jQuery对象,get返回的是所匹配的dom对象,

所有取$("p").eq(1)对象的内容用jQuery方法html()

而取$("p").get(1)的内容用innerHTML