[英]CreateNode not working IE9
我在IE 9上的这段代码中遇到错误。
<!doctype html>
<html>
<head>
<title>Create Node test</title>
</head>
<body>
<script type="text/javascript">
window.onload = function () {
var head = document.getElementsByTagName('head')[0];
var styleEl = document.createElement('style');
var css = "body {};";
if (styleEl.styleSheet){
styleEl.styleSheet.cssText = css;
} else {
styleEl.appendChild(document.createTextNode(css));
}
head.appendChild(styleEl);
}
</script>
</body>
</html>
谁能告诉我我在做什么错? 在Chrome浏览器中工作正常。
谢谢
PS需明确:我想知道为什么这行不通,我不需要修复。 我正在尝试查找IE 9中的错误,我认为这可能与createNode方法和样式元素有关。 有人遇到过此问题吗?或者它是IE9中的已知错误?
您可以随时使用:
<!doctype html>
<html>
<head>
<title>Create Node test</title>
<script type="text/javascript" language="javascript">
window.onload = function () {
var head = document.getElementsByTagName('head')[0];
var styleEl = document.createElement('style');
var css = "body {background-color:red;};";
styleEl.innerHTML = css;
head.appendChild(styleEl);
}
</script>
</head>
<body>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.