在跨度的 onclick 事件中提交表单时如何避免来自浏览器的确认消息?

How to avoid confirmation message from browser when form is submitted at onclick event of a span?

这是JSP页面的初始状态,一组数据是这样的

如果客户单击 + 图标或 单击此处 标签,则应提交表单并增加列表,这将看起来像

单击 + 图标时表单提交是正确的,但是当单击 单击此处 标签时,浏览器要求确认消息

JSP 代码部分是:-

<table width="100%" cellspacing="1" cellpadding="2">
    <tr>
        <td align="center">
            <span style="cursor: pointer;" onclick= "addEvaluators('addEvaluators')">
                <font color="#228B22">Click here</font>&nbsp;
                <img src="images/admission/images/12673199831854453770medical cross button.svg.med.png" width="20px" height="20px" style="vertical-align:middle;">
            </span>
            to increase evaluators
        </td>                                               
    </tr>
    <logic:equal name="paperEvaluationUpdateEntryForm" property="showRemoveButton" value="true">
        <tr>
            <td align="center">
                <span style="cursor: pointer;" onclick="removeEvaluators('removeEvaluators')">
                    <font color="#B22222">Click here</font>&nbsp;
                    <img src="images/admission/images/15107-illustration-of-a-red-close-button-pv.png" width="22px"; height="22px"; style="vertical-align:middle;">
                </span>
                to decrease evaluators
            </td>
        </tr>
    </logic:equal>
</table>

我写的Javascript代码是:-

function addEvaluators(method) {
    document.getElementById("method").value=method;
    document.paperEvaluationUpdateEntryForm.submit();
}

我将图像和标签都保存在 span 标签中的原因是因为我希望 formonclick 事件和 font 标签没有 onclick 事件。

我的问题是为什么点击标签时会出现确认信息,而点击图片时却不会出现,如何避免?

您可以在 onSubmit 方法中添加以下代码

window.onbeforeunload=null;

这将跳过警报功能。