Complete Test code:
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>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> jQuery traverses the same id element and responds to the Message </title>
<Script language = "javascript" src = "http://demo.jb51.net/jslib/jquery/jquery-1.7.2.min.js"> </script>
<Script language = "javascript">
$ (Document). ready (function (){
$ ("[Id = test]"). each (function (){
$ (This). click (function (){
$ (This). val ('click ');
Alert ('triggered the click message! ');
});
});
});
</Script>
</Head>
<Body>
<Label for = "test"> </label>
<Input type = "text" name = "test" id = "test"/>
<Br/>
<Label for = "test"> </label>
<Input type = "text" name = "test" id = "test"/>
</Body>
</Html>