2011-04-25 45 views
0

這裏是我的jQuery爲此代碼添加一個確認?

$('.delete_step').live('click', function(e) { 
e.preventDefault(); 
    var delete_location = window.location.pathname.replace('admin/', '') + '?route=module/cart/delete_step'; 
    $.post(delete_location, { step_id: $(this).attr("rel"), template_number: "<?php print $template_id; ?>" }, 
     function(result) { 
      var token = window.location.search.match(/token=(\w+)/)[1]; 
      window.location.href = window.location.pathname + '/index.php?route=system/template&token=' + token; 
    }); 
}); 

這裏是我的HTML

<span class="delete"><a rel="<?php print $step['step_number']; ?>" class="delete_step" href="#">Delete Step</a></span> 

如何添加一個確認是/否對話框解決這個....任何想法

回答

3

使用window.confirm()

$('.delete_step').live('click', function(e) { 
    e.preventDefault(); 
    if (confirm('Are you sure?')) { 
     // do the $.post() 
    } 
} 
1

像這樣(未測試)

$('.delete_step').live('click', function(e) { 
    e.preventDefault(); 
    var answer = confirm("Are you sure?") 
    if (answer){ 
     var delete_location = window.location.pathname.replace('admin/', '') + '?route=module/cart/delete_step'; 
     $.post(delete_location, { step_id: $(this).attr("rel"), template_number: "<?php print $template_id; ?>" }, 
     function(result) { 
      var token = window.location.search.match(/token=(\w+)/)[1]; 
      window.location.href = window.location.pathname + '/index.php?route=system/template&token=' + token; 
     }); 
    }else{ 
     alert('fail!'); 
    } 
    }); 
0

這將你的函數,然後再繼續問他們:

+0

哈!看起來我被打敗了。 – BraedenP 2011-04-25 17:15:40

1
 
$('.delete_step').live('click', function(e) { 
    e.preventDefault(); 

     if(confirm("Message to be popped up?")) 
     { 
     var delete_location = window.location.pathname.replace('admin/', '') + '?route=module/cart/delete_step'; 
     $.post(delete_location, { step_id: $(this).attr("rel"), template_number: "" }, 
      function(result) { 
       var token = window.location.search.match(/token=(\w+)/)[1]; 
       window.location.href = window.location.pathname + '/index.php?route=system/template&token=' + token; 
     }); 
     } 
    }); 
相關問題