You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除form.form-update的preventDefault()?表单重新激活问题解决

临时禁用表单并确认后提交的解决方案

我需要实现临时禁用表单提交的功能:提交时先校验输入框是否为空,若有空白项则提示数据无效;校验通过则弹出确认弹窗,用户点击确认后再真正提交表单。但在用户确认后,无法解除之前设置的preventDefault()限制,导致表单无法正常提交。

禁用表单的原始代码

var statusForm = true;
$("form.form-update").submit((e)=>{
    e.preventDefault();
    $("form.form-update input").each((key, element) => {
        if (element.value == "") {
            statusForm = false;
        }
    });
    if (statusForm == false) {
        alert("Data is invalid!");
    }
    else{
        // 显示确认弹窗
        $(".confirm-notification").show();
    }
})

确认按钮的初始代码

// 点击"确认"按钮时
$(".confirm-notification-yes").click(()=>{
    // 此处需要编写解除form.form-update的preventDefault()限制的代码
})

问题:如何移除form.form-update的preventDefault()限制?


解决方法

通过结合unbind('submit')和submit()方法可以解决这个问题,最终代码如下:

$(".confirm-notification-yes").click(()=>{
    $("form.form-update").unbind('submit');
    $("form.form-update").submit();
})

内容的提问来源于stack exchange,提问作者gunzxx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 19:45:04