Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML5必需的标签。如何使表格再次有效?_Html_Forms_Validation - Fatal编程技术网

HTML5必需的标签。如何使表格再次有效?

HTML5必需的标签。如何使表格再次有效?,html,forms,validation,Html,Forms,Validation,我正在使用html5属性来验证我的输入。我发现,一旦表单变得无效,它就无法识别用户何时输入了有效信息 例如: <input id="name" type="text" name="username" required oninvalid="setCustomValidity('Please enter a username!')"> 如果用户错过了这个字段,它会突出显示红色,并告诉用户填写它。如果他们随后填写并单击submit,它会告诉用户填写 一旦表单无效,我如何恢复它们?声

我正在使用html5属性来验证我的输入。我发现,一旦表单变得无效,它就无法识别用户何时输入了有效信息

例如:

<input id="name" type="text" name="username" required oninvalid="setCustomValidity('Please enter a username!')">

如果用户错过了这个字段,它会突出显示红色,并告诉用户填写它。如果他们随后填写并单击submit,它会告诉用户填写


一旦表单无效,我如何恢复它们?

声明表单元素无效后,不会重新检查。尝试将空的setCustomValidity字符串添加到oninput。即:

<input id="name" type="text" name="username" required oninvalid="setCustomValidity('Please enter a username!')" oninput="setCustomValidity('')" > 

声明表单元素无效后不会重新检查。尝试将空的setCustomValidity字符串添加到oninput。即:

<input id="name" type="text" name="username" required oninvalid="setCustomValidity('Please enter a username!')" oninput="setCustomValidity('')" > 

我做了一些类似于@Julie answer的事情,但使用onchange而不是oninput

我使用
oninvalid
设置自定义有效错误消息,然后使用
onchange
重置消息,以便表单可以正确提交

<input type="number" oninvalid="this.setCustomValidity('Please enter an INTEGER')" onchange="this.setCustomValidity('')" name="integer-only" value="0" min="0" step="1">

我做了一些类似于@Julie answer的事情,但使用onchange而不是oninput

我使用
oninvalid
设置自定义有效错误消息,然后使用
onchange
重置消息,以便表单可以正确提交

<input type="number" oninvalid="this.setCustomValidity('Please enter an INTEGER')" onchange="this.setCustomValidity('')" name="integer-only" value="0" min="0" step="1">


您尝试过这个吗?谢谢,我搜索过但找不到相关帖子:D您尝试过这个吗?谢谢,我搜索过但找不到相关帖子:D