document.head.appendChild 或 document.createElement 在 IE 中不起作
document.head.appendChild or document.createElement not working in IE
我的html文档的头部运行了一个脚本,它适用于除Internet Explorer以外的所有浏览器。在Opera,Safari,Chrome,Firefox,Internet Explorer中测试。
我的代码如下:
<html>
<head>
<script type = "text/javascript">
var date = new Date();
var month = date.getMonth() + 1;
if (month >= 3 && month <= 5)
{
var NewScript = document.createElement("script");
NewScript.type = "text/javascript";
NewScript.src = "source1.js";
var NewStyles = document.createElement("link");
NewStyles.rel = "stylesheet";
NewStyles.type = "text/css";
NewStyles.href = "css1.css";
document.head.appendChild(NewScript);
document.head.appendChild(NewStyles);
}
else
{
var NewScript = document.createElement("script");
NewScript.type = "text/javascript";
NewScript.src = "source2.js";
var NewStyles = document.createElement("link");
NewStyles.rel = "stylesheet";
NewStyles.type = "text/css";
NewStyles.href = "css2.css";
document.head.appendChild(NewScript);
document.head.appendChild(NewStyles);
}
</script>
</head>
<body>
<!-- MY CONTENT GOES HERE -->
</body>
</html>
我不确定是 document.createElement 还是 document.head.appendChild 在 IE 中不起作用。如前所述,它可以在我测试过的所有其他浏览器中运行。 对此的帮助将不胜感激,因为我将继续自己找到问题/解决方案。谢谢!
尝试document.getElementsByTagName('head')[0]
而不是document.head
> 尝试document.head.appendChild
而不是append
相关文章:
- window.opener.document在ie中不起作用
- document.images未加载在chrome或firefox上,但已加载在IE上
- document.getElementByID 在 IE 8 中不起作用
- 使用document.createElement追加lt IE
- document.body.innerHTML 在 IE 中剥离 JavaScript - bug
- $(document).ready() 在 IE 中使用 require.js 优化代码
- IE document.getElementById
- Javascript:document.images[].complete在IE中不起作用
- document.getElementbyId 在 IE 11 中不起作用
- IE行政命令中的document.write()与其他人不同
- document.head.appendChild 或 document.createElement 在 IE 中不起作
- IE 10,document.links无法使用链接的ID访问,而只能使用索引访问
- document.location.htm在IE中不起作用
- Jquery.scroll()无法在IE中同时使用$(window)和$(document).(window.pageY
- 当document.click事件在Javascript中注册时,如何在IE中正确获取事件目标
- 尝试在内容可编辑的分区中使用document.execCommand粘贴文本.适用于Chrome,而不是IE.我使用的是
- window.parent.document在firefox中工作,但不能在chrome和IE中工作
- 在IE中设置document.domain
- document.getElementById('a').click()没有't在IE工作
- IE在document.cookie.replace.上为cookie添加了两个下划线