Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法使用JavaScript引入Internet Explorer条件注释?_Javascript_Css_Dom_Wicket_Conditional Comments - Fatal编程技术网

有没有办法使用JavaScript引入Internet Explorer条件注释?

有没有办法使用JavaScript引入Internet Explorer条件注释?,javascript,css,dom,wicket,conditional-comments,Javascript,Css,Dom,Wicket,Conditional Comments,我有一段HTML代码,其中包括一条条件注释: <!--[if IE]> <link rel="stylesheet" ...> <[endif]--> 在初始页面呈现时,当包含在页面的头部部分时,此代码经过测试并正常工作 我想在Ajax响应中使用JavaScript向现有页面引入相同的条件CSS 我试过: var comment = document.createComment("[if IE]>\n<link rel=\"styleshee

我有一段HTML代码,其中包括一条条件注释:

<!--[if IE]>
<link rel="stylesheet" ...>
<[endif]-->

在初始页面呈现时,当包含在页面的头部部分时,此代码经过测试并正常工作

我想在Ajax响应中使用JavaScript向现有页面引入相同的条件CSS

我试过:

var comment = document.createComment("[if IE]>\n<link rel=\"stylesheet\" ...>\n<[endif]");
Wicket.Head.addElement(comment); //this is framework code that just appends the element to the HEAD node of the page. I debugged and verified that it's doing the appendChild(...) call.
var comment=document.createComment(“[如果IE]>\n\n你知道吗

另外,在HTML打开标记中使用它也很好(用
js
替换
no-js
!)

也可以通过以下方式在javascript中访问:

if( document.body.className.indexOf("ie") > -1 ){
     //
}

// or using jQuery

if( $(document.body).hasClass("ie6") ){
}

您可以在
innerHTML
中使用条件注释,如下所示:

var div = document.createElement("div");
div.innerHTML = "<!--[if IE]><i></i><![endif]-->";
if (div.getElementsByTagName("i").length) {
    var link = document.createElement("link");
    link.rel = "stylesheet";
    link.type = "text/css";
    link.href = "ie_only.css";
    document.getElementsByTagName("head")[0].appendChild(link);
}
var div=document.createElement(“div”);
div.innerHTML=“”;
if(div.getElementsByTagName(“i”).length){
var link=document.createElement(“链接”);
link.rel=“样式表”;
link.type=“text/css”;
link.href=“ie_only.css”;
document.getElementsByTagName(“头”)[0].appendChild(链接);
}
非常简单:

/*@cc_on document.createStyleSheet("ie.css"); @*/

所有这些都是不必要的

公共无效renderHead(IHeaderResponse响应) if(WebSession.get().getClientInfo().getClientProperties().isBrowserInternetExplorer()){ renderJavaScriptReference(新的JavaScriptResourceReference(MyClass.class,“ie.js”); }


如果您选择使用Modernizer,请注意一件事,您的未替换引号正在破坏您的脚本。请注意
“样式表附近CC字符串的语法突出显示"
。此外,endif标记应该以
开头,而不是
可能会帮助您找到解决方案。特别是,备用样式表部分。@BoltClock:感谢您指出引号;我修复了转义。但这不是问题的原因;在我的实际用例中,注释文本是通过ajax从XML DOM对象加载的,这是一个它是由wicket框架自动转义的。我知道我使用的条件注释字符串不是问题的根源,因为它在内联时可以工作,正如我前面提到的。这看起来解决了问题。我会尝试一下。谢谢!不是严格地回答问题,而是访问相同信息的一种循环方式N
var div = document.createElement("div");
div.innerHTML = "<!--[if IE]><i></i><![endif]-->";
if (div.getElementsByTagName("i").length) {
    var link = document.createElement("link");
    link.rel = "stylesheet";
    link.type = "text/css";
    link.href = "ie_only.css";
    document.getElementsByTagName("head")[0].appendChild(link);
}
/*@cc_on document.createStyleSheet("ie.css"); @*/