Home >Web Front-end >Front-end Q&A >How to disable click elements in jquery

How to disable click elements in jquery

藏色散人
藏色散人Original
2021-11-11 09:35:273861browse

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; }

2. jQuery method

Method one

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

Method two

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

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

Method 3

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

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属性

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!

Statement:
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