Although I have heard of jquery for several years, it has never been used. In the past two days, it seems that jquery is not as studious as it is. 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.
View code
<! 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>