gpt4 book ai didi

jquery - 需要有关 : jquery prepend doctype to html 的帮助

转载 作者:搜寻专家 更新时间:2023-10-31 21:53:36 26 4
gpt4 key购买 nike

这是我的情况:

  1. 我正在编辑应用程序的 CSS 样式表。
  2. 我只能编辑 CSS 样式表(除非我可以创造性地使用 CSS glom 到另一个文件,或者可能在现有的 .js 中添加一个小的 jQuery 前置语句)
  3. 应用程序仅兼容 ie6、ie7 和 ie8。他们从不使用 FireFox,这不是一种选择。

寻求帮助:

1) 我想我需要使用 jQuery 来“prepend/prependTo”一个“doctype”到

html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"

如果没有 !doctype,它会使 ie8 进入 quirksmode,当然不接受任何样式,例如“input[type=checkbox]”

我之前没有使用过prepend。你能帮我用完整和正确的语法来做以下事情吗:

当前:<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

需要:<doctype html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

这对我还没有用 $("html ").prepend("doctype ")

最佳答案

这不是 <doctype html> .这是:

<!DOCTYPE html>
<html (xmlns or any other attributes you want)>

<!DOCTYPE不是一个元素。它有 <!在开头,这对元素无效。这是“doctype 声明”,在初始解析后无法更改。

即使在 DOM 界面允许您移动/替换 DocumentType 的浏览器上表示 doctype 声明的节点,这没有在 Quirks 和 Standards 模式之间切换的效果,这是在初始加载时决定的。您不能在模式之间改变文档。

可以从现有文档加载新文档,但模式已更改:

<!-- no doctype, loads in Quirks Mode (BackCompat) -->
<html>
<!-- rest of the document, then at the end: -->

<script>
alert('now in compatMode '+document.compatMode);
if (document.compatMode==='BackCompat') {
setTimeout(function() {
var markup= document.documentElement.innerHTML;
markup= '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'+markup+'</html>';
document.open();
document.write(markup);
document.close();
}, 0);
}
</script>
</html>

但我强烈建议不要这样做。它很丑陋,会重置任何状态并在加载时间结束时重绘,并且对脚本有各种负面影响。

如果您想要标准模式,您确实需要将文档类型添加到 HTML 本身。如果您绝对不能接触该应用程序,如何使用 ISAPI 过滤器(假设您的 Web 服务器是 IIS)将文档类型添加到它的 HTML 输出中?

关于jquery - 需要有关 : jquery prepend doctype to html 的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4493845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com