Jqyery is equivalent to Windows. onload in Js.

Source: Internet
Author: User

CopyCode The 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 convenience of writing, jquery is better than other applications.ProgramMore popular, but 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 the Dom is loaded, so they can be placed anywhere in HTML, but in some cases, for example, copy Code the code is as follows:

hello, word!




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.