我可以在输入元素中使用自动关闭标签吗? [英] Can I use self-closing tags with input elements?

查看:42
本文介绍了我可以在输入元素中使用自动关闭标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< input> 没有任何子元素,因此在我看来,正确的语法应该是< input/> .现代浏览器支持吗?

<input> doesn't have any child elements, so it seems to me like the proper syntax would be <input/>. Is this supported in modern browsers?

在Chrome中进行快速测试似乎将Chrome将< input/> 转换为< input> .所有浏览器都这样做吗?

A quick test in Chrome seems like Chrome converts <input/> to <input>. Do all browsers do this?

推荐答案

The HTML specification states and clearly shows by example that the proper syntax is <input>. While <input/> is allowed, and called a void element, the closing slash has no meaning, it does nothing and browsers are instructed to ignore it.

如果您担心浏览器的处理方式,那么与往常一样,最好的建议是按照规范的规定进行操作,并始终使用指定且始终有效的< input>

If you are concerned about how a browser will handle it, the best advice, as always, is to do what the specification says to do and always use the specified and always valid <input>.

这篇关于我可以在输入元素中使用自动关闭标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆