In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how jquery removes an event". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to remove an event by jquery".
Jquery remove the event method: 1, use unbind (), syntax "bind event element .unbind (" specify event name ")", remove the specified event of the selected element; 2, use off (), remove the specified event added by on () in the element, syntax "bind event element .off (" event name ")".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Jquery's method of removing an event
Method 1: use the unbind () method
The unbind () method removes the event handler for the selected element.
This method can remove all or selected event handlers, or terminate the operation of the specified function when the event occurs.
Ubind () applies to any event handler attached through jQuery.
Syntax:
The $(selector) .unbind (event,function,eventObj) parameter describes the event optional. Specifies one or more events to remove from the element.
Multiple event values are separated by spaces.
If only this parameter is specified, all functions bound to the specified event are deleted. Function is optional. Specifies the name of the function that specifies the event unbound from the element. EventObj is optional. Specifies the removed event object to use. This eventObj parameter comes from the event binding function.
Example: excluding click events from the element
Function alertMe1 () {alert ("Hello World!") } function alertMe2 () {$("p") .css ("color") "red")} $(document) .ready (function () {$("p") .click (alertMe1) .click (alertMe2)) $("button") .click (function () {$("p") .unbind ("click");})
This is a paragraph.
This is another paragraph.
Click any p element to trigger the alert pop-up window and the font color turns red.
Remove the click event of the p element
Note: since jQuery version 1.7, the on () and off () methods are the preferred methods for adding and removing event handlers on elements.
Method 2: use the off () method
The off () method is typically used to remove event handlers added by the on () method.
Note: to remove the specified event handler, the selector string must match the parameters passed by the on () method when the event handler is added.
Syntax:
The $(selector) .off (event,selector,function (eventObj), map) parameter is required to describe event. Specifies one or more events or namespaces to remove from the selected element.
Multiple event values are separated by spaces. Must be a valid event. Selector is optional. Specifies the selector that is initially passed to the on () method when the event handler is added. Function (eventObj) is optional. Specifies the function to run when an event occurs. Map specifies the event mapping ({event:function, event:function,...}), which contains one or more events to be added to the element, as well as functions to run when the event occurs.
Example:
Function changeSize () {$(this) .animate ({fontSize: "+ = 10px"}) } function changeSpacing () {$(this) .animate ({letterSpacing: "+ = 5px"}) } $(document) .ready (function () {$("p"). On ("click", changeSize); $("p") .on ("click", changeSpacing) $("button") .click (function () {$("p") .off ("click");})
This is a paragraph.
This is another paragraph.
Click any paragraph to change the font size of the paragraph.
Remove the click event
Thank you for your reading, the above is the content of "how jquery removes an event". After the study of this article, I believe you have a deeper understanding of how jquery removes an event, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.