JQuery's read function is implemented in different ways than js's onload Function

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.