本文介绍了html5需要验证器不能与输入类型=按钮一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的html代码
< form id =form1runat =server>
< input id =qrequired />
< input id =btntype =submitvalue =Search>
< / form>
我已经使用了html5所需的字段验证程序,它可以正常工作,但有回发功能。
如此修改代码以避免回传
< form id =form1runat =server >
< input id =qrequired />
< input id =btntype =buttonvalue =Search>
< / form>
但所需的验证器不起作用
这是因为所需的验证器仅在提交时被调用,并且类型=按钮不是提交。试试这个():
< form id =form1runat =server>
< input id =qrequired />
< input id =btntype =submitvalue =Search>
< / form>
Here is my html code
<form id="form1" runat="server">
<input id="q" required />
<input id="btn" type="submit" value="Search">
</form>
I have used html5 required field validators, it works but with a post back.so modified the code as follows to avoid postback
<form id="form1" runat="server">
<input id="q" required />
<input id="btn" type="button" value="Search">
</form>
But the required validator doesn't work
解决方案
That's because the required validator is only called on submit, and the type=button is not a submit. Try this (http://jsfiddle.net/upgradellc/vrTLw/):
<form id="form1" runat="server">
<input id="q" required />
<input id="btn" type="submit" value="Search">
</form>
这篇关于html5需要验证器不能与输入类型=按钮一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
07-25 17:00