Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to cancel a click event by jquery

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to cancel the click event in jquery". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope that this article "how to cancel the click event in jquery" can help you solve the problem.

There are three ways: 1. Use "Click element .unbind ()" to cancel all click events for selected elements. 2. Click the element .off () to cancel the click event added with on () in the selected element. 3. Use "parent element .undelegate ()" to cancel the click event cancelled by delegate ().

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Jquery provides several ways to cancel a click event

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.

This method can also unbind the event handler through the event object. This method is also used to unbind events within themselves (such as deleting event handlers after the event has been triggered a certain number of times).

Example: cancel click event

$(document) .ready (function () {$("p") .click (function () {$(this) .ready ();}) ("button") .click (function () {$("p") .unbind ();});})

This is a paragraph.

This is another paragraph.

Click on any paragraph (p element) and the paragraph will disappear.

Remove a click event on a p element

2. Use the off () method

The off () method is typically used to remove event handlers added by the on () method.

$(document) .ready (function () {$("p") .on ("click", function () {$(this) .ready ();}) ("button") .click (function () {$("p") .off ();});})

3. Use the undelegate () method

The undelegate () method removes one or more event handlers added by the delegate () method.

$(document) .ready (function () {$("body") .delegate ("p", "click", function () {$(this) .ready ();}) $("button") .click (function () {$("body") .undelegate ();})

That's all for "how jquery cancels the Click event". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report