如何使用jQuery或其他方法开发带有“是”和“否”按钮的确认对话框?我需要在单击提交按钮时出现该确认。
如何使用jQuery或其他方法开发带有“是”和“否”按钮的确认对话框?我需要在单击提交按钮时出现该确认。
使用浏览器原生的确认对话框。
if(confirm("Are you sure?"))
{
//Ok button pressed...
}
else
{
//Cancel button pressed...
}
我有一个解决方案,对我来说很有效。
$.alerts.okButton = ' Yes ';
$.alerts.cancelButton = ' No ';
jConfirm('Are you sure??', '', function(r) {
if (r == true) {
//Ok button pressed...
}
});
这将为您提供本地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 );
});
};
有两种不同的使用方式。这些适用于链接或提交输入。
JavaScript:
<input type="submit" formaction="process.php" onclick="return confirm_action();" />
jQuery:
$('#mybutton').confirm_action();