<html>
<body>
<script type="text/javascript" src="jquery.js"></script><noscript></noscript>
<form>
<input type="text" /><br />
<input type="text" /><br />
<input type="button" id="login" />
</form>
<script type="text/javascript">
var login = $("#login");
//var login=document.getElementById('login');
alert(login.id);
</script>
</body>
</html>
alert出的是undefine why?用注释的那个就可以啊
<body>
<script type="text/javascript" src="jquery.js"></script><noscript></noscript>
<form>
<input type="text" /><br />
<input type="text" /><br />
<input type="button" id="login" />
</form>
<script type="text/javascript">
var login = $("#login");
//var login=document.getElementById('login');
alert(login.id);
</script>
</body>
</html>
alert出的是undefine why?用注释的那个就可以啊
[0]: {object}
context: {object}
jquery: "1.3.2"
length: 1
selector: "#login"
你所需要的id是在数组中了。debug一下就知道了
看了 jquery 官方的 tutorials也没看到return是array的!
(http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_item_using_class_or_id.3F) 郁闷
明明写single,但还是返回array 不知道为什么
Matches a single element with the given id attribute.在http://docs.jquery.com/Selectors 看到的 开始奇怪中了 - -!
// alert(elemArr[i].id); //可以
alert(elemArr[i].attr("id")); //不行?