how to develop yes no confirmation using jquery

旧城冷巷雨未停 提交于 2019-11-30 02:56:19

问题


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.


回答1:


Use the native browser confirm dialog.

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



回答2:


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



回答3:


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

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:

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

jQuery:

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

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



来源:https://stackoverflow.com/questions/3166036/how-to-develop-yes-no-confirmation-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!