是否可以忽略 HTML5 验证特定按钮?
Is it possible to ignore HTML5 validation a specific button?
类似于以下问题(请注意以下问题与 symfony 2.3 有关 - 我不知道那是什么,我只是在使用 HTML ) :
How to disable html5-validation for specific buttons in symfony 2.3
是否可以绕过 HTML 中特定按钮的 HTML5 验证 (required
)?
<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");
}
编辑:一种无需更改表单结构或更改按钮即可执行此操作的方法:)。
注册按钮仅使用 <a href="bla">register</a>
或将按钮移出并向输入提交添加表单属性
为注册按钮添加一个点击事件侦听器。当它被点击时,做任何你想做的事(使用 window.location = "....."
重定向),并且 return false 以防止默认提交:
$("#register").on("click", function() {
alert("I am executed before the HTML5 check!");
return false;
});
你可以在这里看到一个例子:http://jsfiddle.net/89z4Lu91/
类似于以下问题(请注意以下问题与 symfony 2.3 有关 - 我不知道那是什么,我只是在使用 HTML ) :
How to disable html5-validation for specific buttons in symfony 2.3
是否可以绕过 HTML 中特定按钮的 HTML5 验证 (required
)?
<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");
}
编辑:一种无需更改表单结构或更改按钮即可执行此操作的方法:)。
注册按钮仅使用 <a href="bla">register</a>
或将按钮移出并向输入提交添加表单属性
为注册按钮添加一个点击事件侦听器。当它被点击时,做任何你想做的事(使用 window.location = "....."
重定向),并且 return false 以防止默认提交:
$("#register").on("click", function() {
alert("I am executed before the HTML5 check!");
return false;
});
你可以在这里看到一个例子:http://jsfiddle.net/89z4Lu91/