2014-01-10 79 views
0

我有兩個鏈接的編輯和刪除按鈕。我想要的是將刪除的編輯確認消息分開。當我點擊編輯按鈕的消息是編輯按鈕,如果刪除按鈕另一個消息顯示。我該怎麼做?添加不同的確認信息jquery

<script> 
jQuery(function ($) { 
    $('a.button.edit, a.button.remove').click(function() { 
     if ($('input[name="checkbox[]"]:checked').length == 0) { 
      return; 
     } 

     if(!confirm('Do you want to continue?')){ 
      return 
     } 

     var frm = document.myform; 
     if ($(this).hasClass('edit')) { 
      frm.action = 'editpr.php'; 
     } 
     if ($(this).hasClass('remove')) {} 
     frm.submit(); 
    }) 
}) 
</script> 

    <a class="button edit" style="cursor:pointer;"><span><b>Edit Purchase Request</b></span></a> 
    <a class="button remove" style="cursor:pointer;" name="remove"><span><b>Remove Purchase Request</b></span></a> 

回答

0

你可以做到這一點,檢查類,並確認消息相應

$('a.button.edit, a.button.remove').click(function() { 
     if ($('input[name="checkbox[]"]:checked').length == 0) { 
      return; 
     } 
     if($(this).hasClass('edit')) { 
      if(!confirm('Do you want to edit?')){ 
      return 
      } 
     else { 
      if(!confirm('Do you want to remove?')){ 
      return 
      } 
     } 

Demo

0
<script> 
jQuery(function ($) { 
    var triggerClick = function(str) { 
     $('a.button.' + str).click(function() { 
      if ($('input[name="checkbox[]"]:checked').length == 0) { 
       return; 
      } 
      if(!confirm('Do you want to continue?')){ 
       return; 
      } 
      var frm = document.myform; 
      frm.action = str + '.php'; 
      frm.submit(); 
     }); 
    }; 
    triggerClick('edit'); 
    triggerClick('remove'); 
}) 
</script>