如何使用javascript/jquery使用多个确认对话框


How to use multiple confirm dialogs using javascript/jquery

你好,我想在点击按钮时放入多个确认对话框,例如,当我点击一个按钮时,它会显示"你确定吗?",显示YES和NO,当我单击YES时,必须打开另一个对话框,显示"想通知用户吗?"

<script>
 $('.deletes').click( function () {  
if (confirm( 'Are you sure? ' ) ) {  
window.location="<?php echo site_url('controller/method'); ?>";
if (confirm( 'want to notify users? ' ) )
{ 
window.location="<?php echo site_url('contoller/method22'); ?>";
} 
} });

</script>

使用以下代码在多次确认后重定向用户

步骤1-在html文件中添加以下行

<button id='open_dialog'>click</button>

步骤2-在js文件中添加以下行-

jQuery('#open_dialog').click( function () {
    if (confirm( 'Are you sure? ' ) ) {
        if (confirm( 'want to notify users? ' ) ) {
            //use statement to redirect on particular page.
        }
    }
})

如果你把你目前拥有的代码放在这里可能会更好,无论如何,请参阅下面的例子:

$('button').click( function () { 
  // first box, if yes then enter if block  
  if (confirm( 'Are you sure? ' ) ) {  
    // again came out 2nd box      
    if (confirm( 'want to notify users? ' ) ) {
        // do something
    }
 }    
});

DEMO