One, page load events
In jquery, the page load event is ready (). The Ready () event is similar to the OnLoad () event in JavaScript, but the former is triggered as soon as the page's DOM structure is loaded, and the latter must be loaded successfully on all elements of the page, which can be written more than once and executed sequentially.
Several ways to do the Ready () method:
Writing one:
$ (document). Ready (function () {
Code section
});
Two:
$ (function () {
Code section
})
Two simple and concise, the use is the most extensive.
Ii. Binding Events
You can use the bind () method to bind events in jquery. The bind () function is the event binding handler for each selection element.
Syntax: $ (selector). bind (Event,[data] function)
The argument event is the event name, and multiple event names are separated by a space, function for the event execution.
Examples are as follows:
<script type="Text/javascript">$ (function(){ $ ("#btnClick"). Bind ("click", function () { $ (this). attr ("Disabled", "true"); })})</script>... Omit code<h3>Bind () method binding Event</h3><input id="Btnclick" type="button" value=" After clicking the button is not available>
Third, switching events
The two methods of hover () and toggle () are provided in jquery for switching between events. The so-called switching event is that there are more than two events bound to an element that switches between the action actions of the element.
Hover () Method:
The function of the hover () method is that when the mouse moves over the selected element, the first function in the method is executed, and when the mouse moves out, the second function in the method is executed to achieve the transition effect of the event.
Syntax form: $ (selector). Hover (over,out);
The over parameter is the function that is moved to the trigger on the selected element, and the out parameter is the functions that are triggered when the element is moved out.
Toggle () Method:
The toggle () method Toggle () method is used to bind two or more event handler functions in response to the selected element's rotation click event.
Syntax form: $ (selector). Toggle (Fun1 (), fun2 (), Funn (),...)
Note: The version of the toggle () method After 1.9.0 is not supported.
can also be used to toggle the Hide () and show () method of the selected element.
Syntax form: $ (selector). Toggle (Speed,callback)
The speed parameter is optional, and the function is to specify the velocity of the hide/show effect; the callback () parameter is optional when the toggle () method completes the function that is executed.
Examples are as follows:
... Omit code<script type="Text/javascript">$( function(){ use of the//hover () method$("Div"). Hover ( function(){$( This). Append ("<B>: Explosive equipment </b>"); }, function(){$("B"). Remove (); } ); })$( function(){//Change the background color for Div$("#btn"). Toggle ( function(){$("Div"). CSS ("Background-color","Green"); }, function(){$("Div"). CSS ("Background-color","Red"); }, function(){$("Div"). CSS ("Background-color","Yellow"); } );}) $( function(){//Show and hide Div$("#btn"). Click ( function(){$("Div"). Toggle ( +); });})</script>... Omit code<h3>Toggle Events</h3><div id="Bindtest">Playing local tyrants</div>Move the mouse up to see<input type="button" id="btn" value="Toggle () method to change the div background color ">... Omit code
Iv. Removal of events
The Unbind () method removes the event handler for the selected element. This method can remove all or the selected event handlers, or terminate the operation of the specified function when the event occurs.
Syntax form: $ (selector). Unbind (Event,function)
Where the parameter event represents the name of the event that needs to be removed, and multiple event names are separated by spaces, and the function arguments are the names of functions called when the event executes.
Introduction to jquery (5)