jquery1.5.1中根据元素ID获取元素对象的代码

尽管听说jquery的大名几年了,但是一直没有使用过。这两天想在项目中使用被一些小细节折腾的够呛,看来jquery没有传说中的那么好学。

在jquery1.5.1根据ID来获取对象返回的是对应数组,想不通怪不得使用document.getElementById(""ID名"")可以取到单一的对象,使用$("#ID名")却不行,悲剧呀。

复制代码 代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> 选择器测试 </title>
<style type="text/css">
.txtobj{background-color: #6600FF;}
</style>
<script type="text/javascript" src="https://www.jb51.net/jquery-1.5.1.min.js"></script>
<script language="JavaScript" type="text/javascript">
$(document).ready(
function()
{
$("input[type='text']")
.click
(
function()
{
this.value=$("#lblMsg")[0].innerText;
}
)
.keydown(
function()
{
alert($("#divTest")[0].innerText);
alert($("#lblMsg")[0].innerHTML);
alert($("#txtTest")[0].value);
return false;
}
);
}
);
</script>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tr>
<td><span>0123456789</span></td>
</tr>
<tr>
<td>
<input type="text" value="@#$message test"/>
</td>
</tr>
</table>
<div>ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>
</body>
</html>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdfgss.html