<输入类型=“隐藏”> 上面的 html dtd

发布于 2024-07-21 04:42:49 字数 393 浏览 12 评论 0 原文

我知道我应该将所有 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">

什么是风险? 到目前为止,我没有任何问题。

I know that I should put all the html elements in body tag, but I need to put two hidden input above html dtd. I guess it does not make my html file as standard, but is it that bad? I have following code.

<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">

what are risks? so far, I do not have any problems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

○愚か者の日 2024-07-28 04:42:49

IIRC,风险是,如果 doctype 不是第一行,IE6 就会遇到问题。 这也不是标准做法,并且可能会导致其他浏览器出现异常(但我相信大多数浏览器应该是宽容的)。

看来您正在使用 XHTML...因此这些输入元素应该是自动关闭的,因为它们没有结束标记。

<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">

他们有什么理由必须在那里吗? 为什么不能将它们放置在 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.

<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">

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 a value attribute, unless you're checking for their existence, or adding the value attribute via JavaScript (which means you could also add these elements themselves via JavaScript).

别忘他 2024-07-28 04:42:49

如果您实际上将其作为 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.

以可爱出名 2024-07-28 04:42:49

风险在于,由于您的文档无效,因此它可能无法在某些浏览器或同一浏览器的不同版本中正确呈现(甚至是当前可能适用的未来版本的浏览器)。

我不确定什么情况可能是这样,您需要这样做。 您想用这种方法解决什么问题,也许还有另一个问题试图解决? :)

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? :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文