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