本文介绍了需要帮助:jquery prepend doctype to html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况如下:


  1. 我在编辑应用程序的CSS样式表。

  2. 我只能编辑CSS样式表(除非我可以创建性地使用CSS浏览另一个文件,或者可能在现有的.js中添加一个小的jQuery前置语句)

  3. 应用程序只有ie6,ie7和ie8兼容。他们从不使用FireFox,它不是一个选项。 寻找帮助:



    1)我认为我需要使用jQuery来prepend / prependTo一个doctypeon

      html xmlns =http://www.w3.org/1999/xhtmllang =enxml:lang =en

    没有!doctype它会将ie8引入到quirksmode中,当然不会接受任何样式,如input [type = checkbox]

    我之前没有使用过prepend。你可以帮助我完整和正确的语法如何进行以下操作:



    CURRENT:< html xmlns =http:// www .w3.org / 1999 / xhtmllang =enxml:lang =en>



    DESIRED:< doctype html xmlns =http://www.w3.org/1999/xhtmllang =enxml:lang =en>



    这对我还不起作用 $(html).prepend(doctype)

    $ b $它不是< doctype html> 。它是:

     <!DOCTYPE html> 
    < html(xmlns或您想要的任何其他属性)>

    <!DOCTYPE 不是元素。它在开始时有<!,这对元素无效。这是doctype 声明,并且在初始解析后它不会被有用地修改。



    即使在DOM接口让你移动的浏览器/替换代表doctype声明的 DocumentType 节点,这不会在Quirks和Standards模式之间改变,这是决定 在初始加载时间。您不能在模式之间变更文档。



    您可以从现有文档加载新文档,但使用更改的模式:

     <! -  no doctype,以怪癖模式加载(BackCompat) - > 
    < html>

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

    但我强烈建议不要。很丑,会重置状态并在加载时间结束时重新绘制,并且对脚本编程有各种负面影响。



    如果您需要标准模式,则需要将doctype添加到HTML本身。如果你完全无法触及应用程序,那么如何使用ISAPI筛选器(假设你的web服务器是IIS)将doctype添加到它的HTML输出中?


    Here's my situation:

    1. I am editing an application's CSS style sheet.
    2. 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)
    3. 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 ")

    解决方案

    It's not <doctype html>. It's:

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

    <!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:

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

    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?

    这篇关于需要帮助:jquery prepend doctype to html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 16:21