MENU

jQuery阻止表单表单submit自动提交

March 16, 2019 • Read: 545 • JavaScript阅读设置

event.preventDefault();不光可以用来阻止表单自动提交,也可以阻止链接!

阻止submit提交:

<form role="form" method="post">
    <div class="form-group mb-3">
        <div class="input-group input-group-merge input-group-alternative">
            <input class="form-control" placeholder="邮箱" name="email" required="" type="email">
        </div>
    </div>
    <div class="form-group">
        <div class="input-group input-group-merge input-group-alternative">
            <input class="form-control" placeholder="密码" name="password" required="" type="password">
        </div>
    </div>
    <div class="text-center">
        <button type="submit" class="btn btn-primary my-4 submit">登录</button>
    </div>
</form>
$("submit").click(function(){
    event.preventDefault();
});
参数描述
event必需。event 参数来自事件绑定函数。