87,992
社区成员
发帖
与我相关
我的任务
分享<input id=aa>
<input id=aa>
<input id=aa>
<script>
var obj=$("input");
alert(obj[0].getAttribute("id"));//aa
alert(obj[1].getAttribute("id"));//aa
alert(obj[2].getAttribute("id"));//aa
alert($("#aa").length);//1,only one
</script>
// HANDLE: $("#id")
} else {
elem = document.getElementById( match[2] );
if ( elem ) {
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem.id !== match[2] ) {
return rootjQuery.find( selector );
}
// Otherwise, we inject the element directly into the jQuery object
this.length = 1;
this[0] = elem;
}
this.context = document;
this.selector = selector;
return this;
}
<input class="myInput" value="1" />
<input class="myInput" value="2" />
<input class="myInput" value="3" />
<input class="myInput" value="4" />
<input class="myInput" value="5" />
<script>
var list = $(".myInput"); // 选择到多个元素时
alert( list[0].value );
alert( list[1].value );
alert( list[2].value );
alert( list[3].value );
alert( list[4].value );
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" >
$(function(){
alert('jquery:'+$('#txt').val());
alert('dom:'+$('#txt')[0].value);
// $('#txt')[0] = document.getElementById('txt')
alert($('form')[0].id);
alert($('form')[1].id);
})
</script>
</HEAD>
<BODY>
<input type='text' id='txt' value='Sandy' />
<form id='form1'>
</form>
<form id='form2'>
</form>
</BODY>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" >
$(function(){
alert('jquery:'+$('#txt').val());
alert('dom:'+$('#txt')[0].value);
// $('#txt')[0] = document.getElementById('txt')
})
</script>
</HEAD>
<BODY>
<input type='text' id='txt' value='Sandy' />
</BODY>
</HTML>