HTML5必填属性似乎不起作用 [英] HTML5 required attribute seems not working
问题描述
我无法弄清为什么HTML5中新的需要属性似乎不起作用,而且我知道我的简单代码似乎没问题。我应该怎么做才能做到这一点?
I can't figure out why the new required attribute of HTML5 seems to not be working, and I know my simple code seems to be okay. What should I do to make this work?
这是我在HTML中的代码:
Here is my code in HTML:
<input type = "text" class = "txtPost" placeholder = "Post a question?" required>
<button class = "btnPost btnBlue">Post</button>
如果我错了,请更正我的错误,但如果我在浏览器中运行代码并单击在文本框中没有任何值的按钮,它应该有一个工具提示显示该字段是必需的,不是吗?但无论您单击按钮多少次都不会发生任何事情。我是否误解了如何使用必需的属性?
Correct me if I'm wrong but, if ever I run the code in the browser and click the button without any value in the textbox it should have a tooltip showing that that field was required, shouldn't it? But nothing happens no matter how many times you click the button. Am I misunderstood on how to use the required attribute?
我在谷歌浏览器版本28.0中运行我的代码。 1500.72
。
推荐答案
尝试将其放入表单标记并关闭输入标记:
Try putting it inside a form tag and closing the input tag:
<form>
<input type = "text" class = "txtPost" placeholder = "Post a question?" required />
<button class = "btnPost btnBlue">Post</button>
</form>
这篇关于HTML5必填属性似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!