jQuery 如何使用jquery开发是不确认

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3166036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:57:43  来源:igfitidea点击:

how to develop yes no confirmation using jquery

jquerymodal-dialog

提问by chetan

How to develop confirmation dialog with yes no button using jquery or any other method ? I need that confirmation when I click on submit button.

如何使用 jquery 或任何其他方法开发带有 yes no 按钮的确认对话框?当我点击提交按钮时,我需要确认。

回答by mck89

Use the native browser confirm dialog.

使用本机浏览器确认对话框。

if(confirm("Are you sure?"))
{
    //Ok button pressed...
}
else
{
    //Cancel button pressed...
}

回答by Sushanth CS

I have a solution, it is working for me.

我有一个解决方案,它对我有用。

     $.alerts.okButton = ' Yes ';
     $.alerts.cancelButton = ' No ';                  
     jConfirm('Are you sure??',  '', function(r) {
       if (r == true) {                    
          //Ok button pressed...
       }  
     });

回答by Stephen R

This will give you both a native JS and jQuery version:

这将为您提供原生 JS 和 jQuery 版本:

function confirm_action( strMessage ) {
    strMessage = (typeof strMessage !== 'undefined') ? strMessage : 'Are you sure you want to do this?';
    return !!confirm( strMessage );
}

$.fn.confirm_action = function ( strMessage ) {
    $(this).click( function(){
        return confirm_action( strMessage );
    });
};

Two different ways to use it. These work on links or Submit inputs.

两种不同的使用方式。这些适用于链接或提交输入。

JavaScript:

JavaScript:

<input type="submit" formaction="process.php" onclick="return confirm_action();" />

jQuery:

jQuery:

$('#mybutton').confirm_action();

Note that in either version you can customize the confirmation message by passing a string parameter.

请注意,在任一版本中,您都可以通过传递字符串参数来自定义确认消息。