1 1.css禁用鼠標點擊事件
2
3 .disabled { pointer-events: none; }
4 注:(這個沒有試過)
5
6
7 jquery禁用a標簽方法1
8 $(document).ready(function () {
9 $("a").each(function () {
10 var textValue = $(this).html();
11 if (textValue == "XX概況" || textValue == "服務導航") {
12 $(this).css("cursor", "default");
13 $(this).attr('href', '#'); //修改<a>的 href屬性值為 # 這樣狀態欄不會顯示鏈接地址 $(this).click(function (event) {
14 event.preventDefault(); // 如果<a>定義了 target="_blank“ 需要這句來阻止打開新頁面
15 });
16 }
17 }); });
18 jquery禁用a標簽方法2
19 $('a.tooltip').live('click', function(event) {
20 alert("抱歉,已停用!");
21 event.preventDefault();
22 });
23 jquery禁用a標簽方法3
24 $(function(){
25 $('.disableCss').removeAttr('href');//去掉a標簽中的href屬性
26 $('.disableCss').removeAttr('onclick');//去掉a標簽中的onclick事件
27 });
28 jquery控制按鈕的禁用與啟用
29
30 控制按鈕為禁用:
31
32 $('#button').attr('disabled',"true");添加disabled屬性
33 $('#button').removeAttr("disabled"); 移除disabled屬性
34
35 live() 方法為被選元素附加一個或多個事件處理程序,並規定當這些事件發生時運行的函數。
36
37 通過 live() 方法附加的事件處理程序適用於匹配選擇器的當前及未來的元素(比如由腳本創建的新元素)。
38
39
40
41 問題:使用jQuery的live()方法綁定事件,有時會出現重復綁定的情況,如,當點擊一個按鈕時,此按鈕所綁定的事件會並執行n遍。
42
43 解決:使用die()方法,在live()方法綁定前,將此元素上的前面被綁定的事件統統解除,然后再通過live()方法綁定新的事件。
44
45
46
47 Js代碼
48 //先通過die()方法解除,再通過live()綁定
49 $("#selectAll").die().live("click",function(){
50 //事件運行代碼
51 });
52 //先通過die()方法解除,再通過live()綁定
53 $("#selectAll").die().live("click",function(){
54 //事件運行代碼
55 });die()方法簡介:
56
57
$('a.tooltip').live('click', function(event) {
3 |
event.preventDefault(); |