<输入类型=“隐藏”> 上面的 html dtd
我知道我应该将所有 html 元素放在 body 标记中,但我需要在 html dtd 上方放置两个隐藏输入。 我想它不会使我的 html 文件成为标准,但是有那么糟糕吗? 我有以下代码。
<input type='hidden' id='current_controller'>
<input type='hidden' id='current_module'>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
什么是风险? 到目前为止,我没有任何问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IIRC,风险是,如果
doctype
不是第一行,IE6 就会遇到问题。 这也不是标准做法,并且可能会导致其他浏览器出现异常(但我相信大多数浏览器应该是宽容的)。看来您正在使用 XHTML...因此这些输入元素应该是自动关闭的,因为它们没有结束标记。
他们有什么理由必须在那里吗? 为什么不能将它们放置在
body
元素内的某个位置? 如果它们没有value
属性,我看不到任何实际用途,除非您检查它们是否存在,或者通过 JavaScript 添加value
属性(意味着您还可以通过 JavaScript 添加这些元素本身)。The risks are, IIRC, that IE6 has trouble with
doctype
if it's not the first line. It's also not standard practice, and could cause quirks in other browsers (but I believe most should be forgiving).It also seems you're using XHTML... therefore those input elements should be self closing as they don't have end tags.
Is there any reason why they must be there? Why can't they be placed inside the
body
element somewhere? I can't see any real use if they don't have avalue
attribute, unless you're checking for their existence, or adding thevalue
attribute via JavaScript (which means you could also add these elements themselves via JavaScript).如果您实际上将其作为 XHTML 提供,并因此让它通过 XML 解析器运行,则它不会呈现,因为标记无效。
If you're actually serving this as XHTML and thus having it run through an XML parser, it won't render as the markup is not valid.
风险在于,由于您的文档无效,因此它可能无法在某些浏览器或同一浏览器的不同版本中正确呈现(甚至是当前可能适用的未来版本的浏览器)。
我不确定什么情况可能是这样,您需要这样做。 您想用这种方法解决什么问题,也许还有另一个问题试图解决? :)
The risks are that since your document is not valid, it will potentially not be rendered correctly in some browsers or in different versions of the same browser (and even future versions of browsers for which this might work currently.)
I'm not sure what the case might be such that you'd need to do this. What problem are you trying to solve with this approach, perhaps there is another question in there trying to get out? :)