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