2012-10-05 80 views
1

我正在使用jquery數據表插件,並在第一行有兩個鏈接。這些鏈接用於點擊發送ajax。由於我實現了datatables(我剛纔有一張桌子),它停止了工作。我環顧四周,想兩件事情:jquery鏈接點擊數據表不工作

我本來

   $(".approveReject").click(function() { 
        OnApproveRejectClick("voavi", this); 
       }); 

而是換成與

$(document).delegate("click", '.approveReject', function (event) { 
alert("clicked"); 
}); 

沒有成功,所以我試圖fnInitComplete回調添加到數據表init對象:

 "fnInitComplete": function() { 
      $(".approveReject").click(function() { 
       OnApproveRejectClick("voavi", this); 
      }); 
     } 

還是什麼都沒有。點擊根本不起作用。任何想法,我需要做什麼才能將點擊事件綁定到我的鏈接?由於

完整的數據表初始化

$("#voaviTable").dataTable({ 
     "bJQueryUI": true, 
     "bScrollInfinite": true, 
     "bScrollCollapse": true, 
     "iDisplayLength": 30, 
     "sScrollY": "450px", 
     "oLanguage": { 
      "sSearch": "Filter: " 
     }, 
     "aaSorting": [], 
     "fnInitComplete": function() { 
      $(".approveReject").click(function() { 
       OnApproveRejectClick("voavi", this); 
      }); 
     } 
    }); 

表例如行:

<tr class="even"> 
<td class=" "> 
<a id="lnkApprove" class="approveReject" href="#">Approve</a> 
| 
<a id="lnkReject" class="approveReject" href="#">Reject</a> 
<span class="ui-icon ui-icon-circle-check" style="display: none;"></span> 
<span class="ui-icon ui-icon-circle-close" style="display: none;"></span> 
<img id="loaderGif" height="16px" style="display: none;" src="../../Content/images/loader.gif"> 
</td> 
<td class="statusID "> 32 </td> 
<td class="statusText "> new </td> 
<td class=" "> </td> 
<td class=" "> </td> 
<td class=" "> Cote de Blancs </td> 
<td class=" "> </td> 
<td class=" "> </td> 
<td class=" "> 
<td class=" "> 10/5/2012 2:54:05 PM </td> 
</tr> 
+0

檢查時,這是射擊。「fnInitComplete」 –

+0

貌似處理程序被綁定多次到同一個事件 –

回答

4

您正在使用委託錯誤

$(document).delegate('.approveReject', "click",function (event) {// <-- notice where the selector and event is 
    alert("clicked"); 
}); 

但如果你正在使用jQuery 1.7+使用。對( )

$(document).on("click", '.approveReject', function (event) { 
    alert("clicked"); 
}); 

最好還是到事件綁定到你的表,雖然,因爲它是(我猜)

$('#voaviTable').on('click','.approveReject', function (event) { 

的$(document).delegate(選擇,事件,數據最接近的靜態父元素,處理程序); // jQuery 1.4.3+

$(document).on(events,selector,data,handler); // jQuery的1.7+

+0

感謝的人!我知道我應該使用,但我沒有時間更改jquery並測試所有內容。你的解決方案工作謝謝 – user576838