In jquery1.5.1, the corresponding array is returned by the object based on the ID. getElementById ("ID name" ") can get a single object. It is a tragedy to use $ (" # ID name.
Copy codeThe Code is as follows:
<! 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> selector test </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>