[英]Not Able to Disable a div On Click by jQuery
Can you please take a look at this code and let me know why I am not able to Disable the div on clicking 您能否看一下这段代码,让我知道为什么我无法在点击时禁用div
$("#test").on("click", function(){ alert("You Clicked On Div."); }); $("#test").prop("disabled", true); $("#test").attr("disabled", 'disabled');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="test"> Click Me </div>
If you are wanting to "turn off" the click, you need to use .off 如果要“关闭”点击,则需要使用.off
$("#test").on("click", function(){
alert("You Clicked On Div.");
$("#test").off("click");
});
If you click once, the alert will fire. 如果单击一次,警报将触发。 Next time it will not as all "click" events have been unbound from any element matching "#test". 下次,它将不会与所有匹配“ #test”的元素解除绑定所有的“ click”事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.