遇到一個屏蔽點擊事件,以前一般都是通過js控制,阻止事件,今天看到css加一個樣式就能屏蔽,來記錄一下
//css禁用鼠標點擊事件 .test { pointer-events: none; }
隨便其他方法也記下吧
1.
e.stopPropatation||e.cancelBubble = true
jquery禁用a標簽
方法1:
$(document).ready(function() { $("a").each(function() { var textValue = $(this).html(); if (textValue == "XX概況" || textValue == "服務導航") { $(this).css("cursor", "default"); $(this).attr('href', '#'); //修改<a>的 href屬性值為 # 這樣狀態欄不會顯示鏈接地址 $(this).click(function(event) { event.preventDefault(); // 如果<a>定義了 target="_blank“ 需要這句來阻止打開新頁面 }); } }); });
方法2
$('a.tooltip').live('click', function(event) { alert("抱歉,已停用!"); event.preventDefault(); });
方法3
$(function() { $('.disableCss').removeAttr('href'); //去掉a標簽中的href屬性 $('.disableCss').removeAttr('onclick'); //去掉a標簽中的onclick事件 });
直接控制標簽禁用
disabled