最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cancel a user click on confirm box 'cancel' - Stack Overflow

programmeradmin4浏览0评论

This is probably a very simple question, but I can't find the answer, so hopefully someone can help?

How do you cancel a click action if the user clicks 'cancel' in a confirm box?

I have this so far but can't find what I need to fill in the blank.

jQuery('#doaction').click(function(e){
    if(jQuery('#bulk-action-selection').val() === 'delete'){
        var action = confirm('Are you sure you wish to delete the selected User Groups? This action cannot be undone.');
    }
    if(action === false){
        { Cancel the click and don't delete the items }
    }
});

This is probably a very simple question, but I can't find the answer, so hopefully someone can help?

How do you cancel a click action if the user clicks 'cancel' in a confirm box?

I have this so far but can't find what I need to fill in the blank.

jQuery('#doaction').click(function(e){
    if(jQuery('#bulk-action-selection').val() === 'delete'){
        var action = confirm('Are you sure you wish to delete the selected User Groups? This action cannot be undone.');
    }
    if(action === false){
        { Cancel the click and don't delete the items }
    }
});
Share Improve this question edited Feb 29, 2012 at 11:11 Lightness Races in Orbit 385k77 gold badges666 silver badges1.1k bronze badges asked Dec 22, 2011 at 9:46 David GardDavid Gard 12.1k42 gold badges128 silver badges261 bronze badges 1
  • 1 If user press cancel just don't do anything? – matino Commented Dec 22, 2011 at 9:49
Add a ment  | 

3 Answers 3

Reset to default 4
 if( action === false )
    return false;

This should work.

Try this:

jQuery('#doaction').click(function(e){
    if(jQuery('#bulk-action-selection').val() === 'delete'){
        var action = confirm('Are you sure you wish to delete the selected User Groups? This action cannot be undone.');
        if(action === false) {
           return false; // this would do
        }
    }
});

Wont this work:

jQuery('#doaction').click(function(e){
    if(jQuery('#bulk-action-selection').val() === 'delete'){
        var action = confirm('Are you sure you wish to delete the selected User Groups? This action cannot be undone.');
    }
    else {
        return false;
    }
});
发布评论

评论列表(0)

  1. 暂无评论