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(); }
Method two
$('a').live('click', function(event) { alert("抱歉,已停用!"); event.preventDefault(); });
Note: This method The live in can also be on, bind and other methods
Method 3
$('.disableCss').removeAttr('onclick');//去掉标签中的onclick事件
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属性
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
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!