2014-01-10 3 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>