需要帮助:jquery prepend doctype to html
这是我的情况:
- 我正在编辑应用程序的 CSS 样式表。
- 我只能编辑 CSS 样式表(除非我可以使用 CSS 创造性地连接到另一个文件,或者可能在现有的 .js 中添加一个小的 jQuery 前置语句)
- 应用程序仅兼容 ie6、ie7 和 ie8。他们从不使用 FireFox,这也不是一个选择。
寻求帮助:
1)我想我需要使用 jQuery 来“prepend/prependTo”一个“doctype”,如果
html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"
没有!doctype,它会将 ie8 抛入怪异模式,当然不接受任何诸如“input[type=checkbox]”之类的样式
我以前没有使用过前置。您能否帮助我使用完整且正确的语法来制作以下内容:
CURRENT:
所需:
这对我来说还不起作用 $("html ").prepend("doctype ")
Here's my situation:
- I am editing an application's CSS style sheet.
- I can ONLY edit the CSS style sheet (unless I can creatively glom onto another file using the CSS, or possibly add a small jQuery prepend statement in an existing .js)
- Application is ONLY ie6, ie7 and ie8 compliant. They never use FireFox, and it's not an option.
Looking for help with:
1) I think I need to use jQuery to "prepend/prependTo" a "doctype " on to
html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"
Without the !doctype it throws ie8 into quirksmode and of course doesn't accept any styles such as "input[type=checkbox]"
I have not used prepend before. Can you help me with full and correct syntax on how to make the following:
CURRENT: <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
DESIRED: <doctype html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
This has not worked for me yet $("html ").prepend("doctype ")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不是
。它是:不是一个元素。它的开头有
,这对于元素来说是无效的。这是“doctype 声明”,在初始解析后无法对其进行有效更改。
即使在 DOM 接口允许您移动/替换表示 doctype 声明的
DocumentType
节点的浏览器上,这也不会产生在 Quirks 和 Standards 模式之间进行更改的效果,而这只是由 决定的 在初始加载时。您无法在模式之间改变文档。您可以从现有文档加载新文档,但模式已更改:
但我强烈建议不要这样做。它很难看,会重置任何状态并在最后重绘加载时间,并且对脚本编写有各种负面影响。
如果您想要标准模式,您确实需要将文档类型添加到 HTML 本身。如果您绝对无法接触应用程序,那么使用 ISAPI 过滤器(假设您的 Web 服务器是 IIS)将 doctype 添加到其 HTML 输出怎么样?
It's not
<doctype html>
. It's:<!DOCTYPE
is not an element. It has<!
at the start, which is invalid for an element. This is the the “doctype declaration”, and it cannot usefully be altered after initial parsing.Even on browsers whose DOM interfaces let you move/replace the
DocumentType
node representing the doctype declaration, this does not have the effect of changing between Quirks and Standards mode, which is something that is decided only at initial load time. You cannot mutate a document between modes.You can load a new document from the existing document but with a changed mode:
But I would strongly advise against it. It's ugly, will reset any state and redraw at the end of load time, and has all sorts of negative implications for scripting.
If you want Standards Mode, you really need to be adding the doctype to the HTML itself. If you absolutely can't touch the application, how about using an ISAPI filter (assuming your web server is IIS) to add the doctype to its HTML output?