Jqyery is equivalent to windows. onload in js.

Source: Internet
Author: User

Copy codeThe Code is as follows:
$ (Function () {// script })
Jquery (function () {// script })
Jquery (document). ready (function () {// script })

The above three codes execute the same action. because of the ease of writing, Jquery is more popular than other applications. However, when used with other js libraries, especially prototype. when using js at the same time, you cannot use the $ method, because they also have this method, you can use the following method to avoid this conflict:

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

They are all operations performed after Dom loading, so they can be placed anywhere in html, but in some cases, such as the loading event method mentioned in the previous section
Copy codeThe Code is 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 = "Modify 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>

It is executed during the loading process, that is, the relevant elements must be loaded before they can be executed. If they are put in the above code, it will be much more flexible.
Copy codeThe Code is 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 = "Modify 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 in any location...

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.