工作中遇到這種情況:驗證郵箱頁面的重新發送需要在3分鐘后才可以點擊重新發送,所以在這之前需要禁用他的點擊
網上查了后有一下幾種實現方法
1.CSS禁用鼠標點擊事件
.disabled { pointer-events: none; }
注:(這個沒有試過)
| 01 | $(document).ready(function() { | 
| 02 |         $("a").each(function() { | 
| 03 |             vartextValue = $(this).html(); | 
| 04 |             if(textValue == "XX概況"|| textValue == "服務導航") { | 
| 05 |                 $(this).css("cursor", "default"); | 
| 06 |                 $(this).attr('href', '#');     //修改<a>的 href屬性值為 #  這樣狀態欄不會顯示鏈接地址   | 
| 07 |                 $(this).click(function(event) { | 
| 08 |                     event.PReventDefault();   // 如果<a>定義了 target="_blank“ 需要這句來阻止打開新頁面 | 
| 09 |                 }); | 
| 10 |             } | 
| 11 |         }); | 
| 12 | }); | 
| 1 | $(function(){ | 
| 2 | $('.disableCss').removeAttr('href');//去掉a標簽中的href屬性 | 
| 3 | $('.disableCss').removeAttr('onclick');//去掉a標簽中的onclick事件 | 
| 4 | }); | 
控制按鈕為禁用:
| 1 | $('#button').attr('disabled',"true");添加disabled屬性  | 
| 2 | $('#button').removeAttr("disabled"); 移除disabled屬性 | 
live() 方法為被選元素附加一個或多個事件處理程序,并規定當這些事件發生時運行的函數。
通過 live() 方法附加的事件處理程序適用于匹配選擇器的當前及未來的元素(比如由腳本創建的新元素)。
問題:使用jQuery的live()方法綁定事件,有時會出現重復綁定的情況,如,當點擊一個按鈕時,此按鈕所綁定的事件會并執行n遍。
解決:使用die()方法,在live()方法綁定前,將此元素上的前面被綁定的事件統統解除,然后再通過live()方法綁定新的事件。
Js代碼
//先通過die()方法解除,再通過live()綁定
$("#selectAll").die().live("click",function(){
//事件運行代碼
});
//先通過die()方法解除,再通過live()綁定
$("#selectAll").die().live("click",function(){
  //事件運行代碼
 });die()方法簡介:
新聞熱點
疑難解答