开发者

adding a confirm to this code?

Here is my 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;
  });
});

Here is my HTML

<span class="delete"><a rel="<?php print $step['step_number']开发者_运维百科; ?>" class="delete_step" href="#">Delete Step</a></span>  

How do I add a confirm yes/no dialog box around this....any ideas


Use window.confirm().

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


Something like this (not tested)

$('.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!');
   }
    });


$('.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;
      });
       }
    });


This will ask them before continuing with your function:

$('.delete_step').live('click', function(e) {
    e.preventDefault();
    var response = confirm("Are you sure you want to delete this?");
    if(response){
        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;
        });
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜