我有一段 HTML 代码,其中包含条件注释:
<!--[if IE]>
<link rel="stylesheet" ...>
<[endif]-->
当包含在页面的 HEAD 部分中时,在初始页面呈现时,此代码已经过测试并且可以正常工作。
我想在 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.
上面的代码不会导致样式表在 Internet Explorer 7 中应用。有没有办法使用 JavaScript 以 Internet Explorer 理解的方式引入条件样式?
为了清楚起见,我正在尝试使用 JavaScript 创建条件样式,而不是尝试编写浏览器条件 JavaScript。