DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> jquery1.5.1中根據元素ID獲取元素對象的代碼
jquery1.5.1中根據元素ID獲取元素對象的代碼
編輯: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="../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 width="400" border="1" cellpadding="0" cellspacing="0">
<tr>
<td><span id="lblMsg">0123456789</span></td>
</tr>
<tr>
<td>
<input type="text" id="txtTest" class="txtobj" value="@#$message test"/>
</td>
</tr>
</table>
<div id="divTest">ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>
</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved