html5 required validator not working with input type=button

為{幸葍}努か 提交于 2019-12-18 06:07:14

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/17163023/html5-required-validator-not-working-with-input-type-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!