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...