简体   繁体   English

需要HTML5输入表单

[英]HTML5 input form required

I'm trying to figure out if a html5 input using required needs to have the self closing tag or not. 我试图弄清楚使用所需的html5输入是否需要具有自动关闭标签。

<input id="email_input" type="email" class="mim-text-input" required>

versus

<input id="email_input" type="email" class="mim-text-input" required />

According to the W3C validator , both of those options are valid HTML5. 根据W3C验证程序 ,这两个选项都是有效的HTML5。

在此处输入图片说明

You're OK on both accounts: both are valid. 两个帐户都可以:两个都有效。

In the HTML5 syntax specification it clearly shows inputs without the trailing slash. HTML5语法规范中,它清楚地显示了输入,但没有结尾斜杠。

However, either are valid. 但是,两者均有效。 The trailing slash can be used and is still considered valid to allow for easier compatibility between xHTML/HTML4 developments. 可以使用尾部斜杠, 但仍认为该斜杠有效,以使xHTML / HTML4开发之间的兼容性更容易。

You could always run your code through the W3 Validator to be absolutely sure. 您绝对可以始终通过W3验证程序运行代码。

All that said, however, there's no promise that browser default behaviors aren't effected differently based on syntax so it's very much a case of user beware . 但是,所有这些都不能保证浏览器的默认行为不会因语法而受到不同的影响,因此在很大程度上要提防用户

By default it is convention used: 默认情况下,使用惯例:

<input/> or <input> </ input>, 

the reason is to indicate the end of the statement. 原因是表明声明的结尾。 A tag that has more content inside eg: 标签内部包含更多内容,例如:

<textarea> content </ textarea>.

A tag that has no content in and often and is defined only by their attributes eg: 一个标签,通常不包含任何内容,并且仅由其属性定义,例如:

<input/>.
<input> without </ input>

Works, only in HTML5 when a tag that has more content inside, in other HTML previous works because the browser or framework fixes for you. 仅当HTML5中包含更多内容的标记有效时,此方法才有效;而在其他HTML早期版本中,则有效,因为浏览器或框架已为您修复。 As you can see in the generated source code. 如您所见,在生成的源代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM