How to disable click elements in jquery

藏色散人
Release: 2021-11-11 09:35:27
Original
3835 people have browsed it

Jquery prohibits clicking on elements: 1. Through "$(this).click(function (event) {...}"; 2. Through "$('a').live( 'click', function(event) {...}" method, etc.

How to disable click elements in jquery

The operating environment of this article: windows7 system, jquery version 3.2.1, DELL G3 Computer

jquery How to prohibit clicking on an element?

Removing or disabling the click event of an html element can be achieved through css or through js or jQuery.

1. CSS method

.disabled { pointer-events: none; }
Copy after login

2. jQuery method

Method one

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

Method two

$('a').live('click', function(event) {
   alert("抱歉,已停用!");
   event.preventDefault();
});
Copy after login

Note: The live in this method can also be on, bind and other methods

Method 3

$('.disableCss').removeAttr('onclick');//去掉标签中的onclick事件
Copy after login

Use the removeAttr method to control the attribute of the html tag to enable or disable the event. In addition , you can also use this method to control other events or other effects.

Method 4

$('#button').attr('disabled',"true");//添加disabled属性
$('#button').removeAttr("disabled"); //移除disabled属性
Copy after login

Note: It is the same as method 3, but the disabled attribute is generally used in Recommended learning for input types of button or submit: "

jquery video tutorial

"

The above is the detailed content of How to disable click elements in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template