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