是否可以忽略特定按钮的HTML5验证


Is it possible to ignore HTML5 validation a specific button?

类似于以下问题(注意以下问题与symfony 2.3有关 - 我不知道那是什么,我只是在使用HTML):

如何在symfony 2.3中禁用特定按钮的html5验证

是否可以绕过HTML5验证(required)来获取HTML中的特定按钮?

<form name="loginform" autocomplete="off" id="loginform" action="" method="post">
            <nav class="clearfix">
                <ul class="clearfix">
                    <li><input class="username" type="text" id="username" required placeholder="Username"></li>
                    <li><input class="password" type="password" id="password" required placeholder="Password"></li>
                    <li><button name="register" class="register">Register</button>
                    <button name="login" class="login">Log in</button></li>
                </ul>
                <a href="#" id="pull">Menu</a>
            </nav>
    </form>

如果单击注册按钮,则不需要验证。

if(isset($_POST['register'])) {
    header("Location: register.php");
}

编辑:一种无需更改窗体结构或更改按钮:)即可执行此操作的方法。

将单击事件侦听器添加到注册按钮。单击它时,执行任何您想要执行的操作(使用 window.location = "....." 重定向),并返回 false 以防止默认提交:

$("#register").on("click", function() {
    alert("I am executed before the HTML5 check!");
    return false;
});

您可以在此处查看示例:http://jsfiddle.net/89z4Lu91/

到注册按钮只使用<a href="bla">register</a>或把波顿放出来,输入提交添加表格 attr