如何使用jquery开发是否确认

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

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

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的:

  

jQuery的:

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

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