Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript如何在JSP上使用带有两个提交按钮的提交确认对话框_Javascript_Jsp_Confirm_Onsubmit - Fatal编程技术网

Javascript如何在JSP上使用带有两个提交按钮的提交确认对话框

Javascript如何在JSP上使用带有两个提交按钮的提交确认对话框,javascript,jsp,confirm,onsubmit,Javascript,Jsp,Confirm,Onsubmit,我的表单目前有两个提交按钮。一个用于搜索,另一个用于标记完成功能。我只需要在单击“标记完成”按钮提交表单并通过验证时显示确认对话框。是否有可能确定这一点?我目前拥有以下confirmplete功能: function confirmComplete() { alert("confirmComplete"); var answer=confirm("Are you sure you want to continue"); if (answer==true) { return true;

我的表单目前有两个提交按钮。一个用于
搜索
,另一个用于
标记完成
功能。我只需要在单击“标记完成”按钮提交表单并通过验证时显示确认对话框。是否有可能确定这一点?我目前拥有以下
confirmplete
功能:

function confirmComplete() {
alert("confirmComplete");
var answer=confirm("Are you sure you want to continue");
if (answer==true)
  {
    return true;
  }
else
  {
    return false;
  }
}

任何帮助都将不胜感激

您需要通过单击按钮而不是表单提交来执行事件。没有交叉浏览的方法可以知道提交表单的内容

将“标记完成”按钮的
onclick
属性设置为

 onclick="return confirm('Are you sure you want to continue')" 

并从表单中删除confirmplete函数,您可以这样做。你可以像这样扣上你的钮扣

<input type="submit" value="Search" />
<input type="submit" value="Mark Complete" onclick="{return confirmComplete();}" />


单击“标记完成”按钮后,将调用“
确认完成”
功能,当用户在确认对话框中说“确定”时,将只提交表单。

因此这里有一个绕过解决方案:

<form id="frm" action="page.php" method="post" onsubmit="return onSubmit();">
    <input />
    <input type="submit" value="sub1" onclick="sub1();" />
    <input type="submit" value="sub2" onclick="sub1();" />
</form>
 <script type="text/javascript">
<!--
var frm = document.getElementById('frm');
function onSubmit(){
    return false;
}

function sub1(){
    alert('s1');
    frm.submit();
}

function sub2(){
    alert('s2');

}
 //-->
 </script>

当您调用“confirm()”javascript弹出函数时,如onclick=“return confirm('您确定要继续吗?”)”,确认框get显示消息“您确定要继续吗?”以及两个选项“确定”和“取消”。单击“确定”时,返回true并继续执行网页;单击“取消”时,返回false并停止进一步执行网页

我不知道输入标记的用法,但直接在按钮上单击事件对我不起作用。就我而言,表格马上就被张贴了

对于具有多个按钮(其中只有一个按钮必须显示确认消息)的表单,这里有一个可能的解决方案

他认为:

<FORM name="F_DESTINATION_DB" id="F_DESTINATION_DB" method="POST" onsubmit="return popConfirmationBox('<?php echo LanguageControler::getGeneralTranslation("DELETE_CONFIRMATION_MESSAGE", "Deleting is an irreversible action. Are you sure that you want to proceed to the deleting?");?> ','DELETE_DB_BUTTON')">
我很难做到这一点(需要大量的研究和测试),但结果代码非常简单

默认情况下,我假设确认为yes(如果单击的按钮不是用于显示消息的按钮,或者如果用户没有提供有效的消息字符串)

附加说明:当然,如果用户浏览器阻止客户端代码,则此代码不会起作用

我希望它能帮助别人


Montreal的Jonathan Parent-Lévesque

您只能使用javascript-将提交按钮设置为常规按钮type=“button”将每次单击的按钮设置为不同的函数,如果要提交表单,只需使用javascript:[form_元素].submit();我必须将它们保留为type=“submit”,因为其他功能已经到位。有趣的解决方案。下面显示的返回确认方法是最简单的方法。
/**
* Display a confirmation message box to validate if we must post the page or not.
*
* @param message String to display
* @param tagId String id of the tag that must display the message.
*
* @return Boolean (confirmation)
*/  
function popConfirmationBox(message, tagId){

    var confirmation = true;

    if (typeof tagId === 'string' && document.activeElement.id.toUpperCase() === tagId.toUpperCase()) {

        if (typeof message === 'string' && message.length > 0) {

            confirmation = window.confirm(message);
        }
    }

    return confirmation;
}