1, $ (document). The difference between the ready () method and the Window.onload method
$ (document). Ready (function(){ //Code })//Shorthand//$ (function () {////Code// });window.onload=function(){ //Code }//equivalent to//$ (window). Load (function () {////Code// })
① execution Time: The former can be called when the DOM is fully ready, which is executed when all the elements in the Web page (including all associated files of the element) are fully loaded into the browser, that is, JavaScript can now access any element in the page. (Note: The former when the HTML related to the picture has been parsed into a DOM tree, but it is possible that the picture is not loaded, the height and width of the picture is not necessarily valid at this time, using the load () method, the equivalent of JS's onload ())
② multiple use: The latter JavaScript onload event can only hold a reference to a function at a time. The former can be executed sequentially.
2. Event Binding
$ (function () { $ (function () { var $content = $ ( This ). Next (); if ($content. Is (": Visible")) { $content. Hide (); Else { $content. Show (); } ); });
3. Change the Binding event type
"Sharp jquery" events in jquery