Home > Web Front-end > JS Tutorial > body text

Detailed explanation of jQuery operating html element click event

php中世界最好的语言
Release: 2018-04-23 16:48:56
Original
3111 people have browsed it

This time I will bring you a detailed explanation of the click event of jQuery operation html element , what are the precautions for jQuery operation of html element click event, the following is a practical case, let's take a look .

Removing or disabling click events of html elements 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();
}
Copy after login

Method two

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

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

Method 3

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

Control the html tag through the removeAttr methodThe property has been reached to enable or disable events. In addition, other events or other effects can also be controlled using this method.

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 on inputs of type button or submit.

PS: Here is an online comparison table of javascript common events and function descriptions for your reference:

## I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Summary of jquery’s time acquisition method

##What are the precautions for jQuery version upgrade

The above is the detailed content of Detailed explanation of jQuery operating html element click event. 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