如何使用javascript函数在提交表单元素时提供确认对话框

如何使用javascript函数在提交表单元素时提供确认对话框,javascript,Javascript,Html代码: <form action='save.php' method="post" onsubmit="return validate(this)"> some inputs here... </form> 确认显示对话框,但单击“确定”按钮后,它不会提交表单。是否有任何方法可以使用javascript函数在确认对话框上提交表单。提前感谢。根据要求,回答我的评论: 将表单验证函数编写为: function validate(theForm){ //v

Html代码:

<form action='save.php' method="post" onsubmit="return validate(this)">
  some inputs here...
</form>

确认显示对话框,但单击“确定”按钮后,它不会提交表单。是否有任何方法可以使用javascript函数在确认对话框上提交表单。提前感谢。

根据要求,回答我的评论:

将表单验证函数编写为:

function validate(theForm){
    //validation stuff here
    return confirm('Are you sure you want to proceed?');
}

旁注:为什么不直接执行
返回确认('you sure?')
而不是整个if-else检查呢?一个简单的内联JavaScript确认就可以了。例如,
什么不起作用?谢谢tewathia,工作正常。:)@不一定是DipeshParmar,因为函数验证所有输入。然而,正如tewathia所说,if-else可以用该行替换。
function validate(theForm){
    //validation stuff here
    return confirm('Are you sure you want to proceed?');
}