Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery forbids clicking on elements

Shulou Source: shulou.com Published: 2022-06-02 16:23:15 09月16日 Update

This article mainly explains "how jquery prohibits clicking elements". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how jquery prohibits clicking elements" together!

jquery Forbidden click element implementation method: 1, by "$(this).click(function (event) {...} "way;2. by"$('a ').live ('click', function(event) {...} "Manner, etc.

Operating environment: Windows 7 system, jquery3.2.1 version, DELL G3 computer

How does jquery prohibit clicking elements?

Click events to remove or disable html elements can be implemented through CSS or js or jQuery.

1. CSS method

.disabled { pointer-events: none; }

2. jQuery method

method one

$(this).click(function (event) {event.preventDefault();}

methodology II

$('a').live('click', function(event) { alert("Sorry, this is disabled! "); event.preventDefault();});

Note: Live in this method can also be on, bind, etc.

method three

$('. disableCss').removeAttr ('onclick ');//remove onclick event from tag

Control the html tag's properties by removeAttr method has reached enable or disable event. In addition, other events or effects can be controlled in this way.

method four

$('#button').attr ('disabled ',"true");//add disabled attribute $('#button').removeAttr ('disabled'); //remove disabled attribute

Note: Same as method 3, except disabled attribute is generally used on input of type button or submit

Thank you for reading, the above is "jquery how to prohibit clicking elements" content, after the study of this article, I believe we have a deeper understanding of how jquery prohibits clicking elements, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Methods elements events attributes methods learning content can be passed tags controls sorry that is ideas situations effects articles more this method environment computer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi MariaDB vpn Redmi