Onload Implementation of js:
Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Use of js onload method </title>
<Script type = "text/javascript">
Window. onload = function (){
Var myLinks = document. getElementsByTagName ("");
For (var I = 0; I <myLinks. length; I ++ ){
MyLinks [I]. onclick = function (){
Alert ("connected ");
}
}
}
</Script>
</Head>
<Body>
<H1> Use of js onload method <A href = "#"> link 1 </a> <br/>
<A href = "#"> link 2 </a> <br/>
<A href = "#"> link 3 </a> <br/>
<A href = "#"> Link 4 </a> <br/>
<A href = "#"> link 5 </a> <br/>
<A href = "#"> link 6 </a> <br/>
</Body>
</Html>
Implementation of jquery's ready Method:
Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Use of the ready method 2 </title>
<Script type = "text/javascript" src = "jquery-core/jquery-1.8.0.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("A"). click (function (){
Alert ("connected! ");
});
});
</Script>
</Head>
<Body>
<H1> Use of the ready method 2 <A href = "#"> link 1 </a> <br/>
<A href = "#"> link 2 </a> <br/>
<A href = "#"> link 3 </a> <br/>
<A href = "#"> Link 4 </a> <br/>
<A href = "#"> link 5 </a> <br/>
<A href = "#"> link 6 </a> <br/>
</Body>
</Html>