2013-01-23 74 views
0

如何確認刪除jquery中選定的數據,我可以把確認對話框通知用戶。 我希望用戶被問及是否要刪除。 下面的代碼完美的工作,但我希望它與該功能。在jQuery中的確認對話框

<script type="text/javascript"> 
$(document).ready(function() { 
    $('a.delete').click(function (e) { 
     e.preventDefault(); 
     var parent = $(this).parent(); 
     $.ajax({ 
      type: 'POST', 
      url: 'delete.php', 
      data: 'ajax=1&delete=' + parent.attr('id').replace('record-', ''), 
      beforeSend: function() { 
       parent.animate({ 
        backgroundColor: '#fbc7c7' 
       }, 300) 
      }, 
      success: function() { 
       parent.slideUp(300, function() { 
        parent.remove(); 
       }); 
      } 
     }); 
    }); 
}); 
</script> 
+0

使用提示框.. – Deadlock

回答

1

使用jQueryUI的對話框,它適用於要求符合你的完美的罰款,是指here

2

只需像這樣的東西換你的實際行動:

如果(確認(「你}){/ *這裏的動作* /}

編輯:或者使用jQuery對話框進行友好的用戶交互,因爲Chris建議使用

1
<script type="text/javascript"> 
$(document).ready(function(){ 
$('a.delete').click(function(e){ 
e.preventDefault(); 
if(confirm("do you want to delete this record ?")){ 
    var parent = $(this).parent(); 
    $.ajax({ 
    type: 'POST', 
    url: 'delete.php', 
    data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), 
    beforeSend: function(){ 
    parent.animate({backgroundColor:'#fbc7c7'},300) 
    }, 
    success: function(){ 
    parent.slideUp(300,function(){ 
     parent.remove(); 
    }); 
    } 
    }); 
} 
}); 
}); 
</script> 
1
$('<div></div>').appendTo('body') 
        .html('<div><h6>Are you sure?</h6></div>') 
        .dialog({ 
         modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true, 
         width: 'auto', resizable: false, 
         buttons: { 
          Yes: function() { 
           // Do ajax request $(obj).removeAttr('onclick');         
           // $(obj).parents('.Parent').remove(); 

           $(this).dialog("close"); 
          }, 
          No: function() { 
           $(this).dialog("close"); 
          } 
         }, 
         close: function (event, ui) { 
          $(this).remove(); 
         } 
        }); 
0

您可以使用確認對話框中,每當用戶會點擊刪除鏈接,它會問你是否真的要刪除嗎?如果答案沒問題,則返回true。

代碼是這樣的。

<script type="text/javascript"> 
$(document).ready(function(){ 
$('a.delete').click(function(e){ 
    e.preventDefault(); 
    var parent = $(this).parent(); 

    var check = confirm("Do you want to delete ?"); 
    if(check == true) 
    { 
     $.ajax({ 
      type: 'POST', 
      url: 'delete.php', 
      data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), 
      beforeSend: function(){ 
       parent.animate({backgroundColor:'#fbc7c7'},300) 
      }, 
      success: function(){ 
       parent.slideUp(300,function(){ 
       parent.remove(); 
      }); 
      } 
     }); 
    } 
}); 
}); 
</script> 
+0

非常感謝這個答案工作4我100% – Musa