我使用AJAX使用jquery,我使用下面的代碼片段刪除行:確認框超過一次出現
$('#example a.delete'). live('click', function (e) {
e.preventDefault();
if (confirm("Are you sure you want to delete this row?"))
{
alert("Hello World!")
}
});
當我點擊網格視圖顯示按鈕,網格視圖顯示無頁由於ajax令人耳目一新。如果我多次點擊網格視圖顯示按鈕,則會相應地再次刷新網格視圖區域。但確認框顯示不止一次,這等於我的號碼。點擊網格視圖顯示按鈕,當我點擊單行刪除按鈕。
如何避免這一點!
編輯
HTML代碼:
<td><a class="delete" href="#" style="margin-left: 10px"><img src="images/delete-icon.png" width="16px" height="16px" /></a></td>
編輯
完整的代碼段:
$('#example a.delete'). live('click', function (e) {
e.preventDefault();
if (confirm("Are you sure you want to delete this row?"))
{
$getCode = $(this).parent().parent().attr('id');
var oTable = $('#example').dataTable();
var index =oTable.fnGetPosition(document.getElementById($getCode));
$.post("DeleteDepartment", {
depID:$getCode
}, function(data) {
if(data.result >0){
var oTable = $('#example').dataTable();
oTable.fnDeleteRow(index);
}else{
alert("Operation Fail");
}
});
}
});
你用的是什麼jQuery版本? –
jQuery v1.7.1 @ltiong_sh –