The application of windows.onload in the same and JS in Jqyery _jquery

Source: Internet
Author: User
Copy Code code as follows:

$ (function () {//script})
Jquery (function () {//script})
Jquery (document). Ready (function () {//script})

The above three code performs the same action, and because it is easy to write, jquery is more popular than other applications, but when used with other JS libraries, especially when used by prototype.js, you cannot use the $ method because they also have this method, You can avoid this conflict in the following ways:

JQuery (function ($) {//script})

They are all done after the DOM is loaded, so anywhere in the HTML, but in some cases, such as the method of loading events mentioned in the previous section
Copy Code code as follows:

<div id= "Divinfo" >Hello,Word!</div>
<input id= "btnshow" type= "button" value= "Display"/>
<input id= "Btnhid" type= "button" value= "Hide"/>
<input id= "Btnchange" type= "button" value= "modified to: Hello"/>
<script type= "Text/javascript" >
$ ("#btnShow"). Bind ("click", Function (event) {$ ("#divInfo"). Show ()});
$ ("#btnHid"). Bind ("click", Function (event) {$ ("#divInfo"). Hide ();};
$ ("#btnChange"). Bind ("click", Function (event) {$ ("#divInfo"). html ("Hello");};
</script>

This is done in the loading process, it is necessary to load the relevant elements to execute, if you put them in the above code is more flexible
Copy Code code as follows:

<div id= "Divinfo" >Hello,Word!</div>
<input id= "btnshow" type= "button" value= "Display"/>
<input id= "Btnhid" type= "button" value= "Hide"/>
<input id= "Btnchange" type= "button" value= "modified to: Hello"/>
<script type= "Text/javascript" >
JQuery (function ($) {$ ("#btnShow"). Bind ("click", Function (event) {$ ("#divInfo"). Show ()});
$ ("#btnHid"). Bind ("click", Function (event) {$ ("#divInfo"). Hide ();};
$ ("#btnChange"). Bind ("click", Function (event) {$ ("#divInfo"). html ("Hello");})
})
</script>

So this loading event can be placed anywhere ...
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.