我有一个脚本在我的HTML文档的头部运行,它在每个浏览器工作,除了IE浏览器。 经测试在Opera,Safari浏览器,Chrome浏览器,火狐,IE浏览器。
我的代码如下:
<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>
我不知道,如果它是不工作在IE中使用document.createElement或document.head.appendChild。 如前所述,它在,我已经在测试了它的所有其他浏览器。这方面的帮助将不胜感激,因为我会继续发现问题/解决方案自己。 谢谢!