gpt4 book ai didi

javascript - setAttribute 在 ie 上不起作用,有什么解决方法吗?

转载 作者:行者123 更新时间:2023-12-02 19:49:03 25 4
gpt4 key购买 nike

这是我的代码。它在 Firefox 上运行良好

<script language="JavaScript"type="text/javascript">
window.onload=function createDiv()
{
var body = document.getElementsByTagName('body') [0];
var div = document.createElement('div');
div.setAttribute('id','errorMessage');
div.setAttribute('class','blockMessage');
var text = document.createTextNode('TO close the message click on cancel');
var closeText=document.createElement('span');
closeText.setAttribute('id','close');
closeText.setAttribute('onclick','destroyObject()');
var text1=document.createTextNode('Close');
closeText.appendChild(text1);
div.appendChild(text);
div.appendChild(closeText);

document.body.insertBefore(div, document.body.firstChild);

//body.appendChild(div);
}
function destroyObject(){
var getId=document.getElementById('errorMessage');
getId.remove(getId);
}

</script>

最佳答案

作为解决方法,如果是 IE,您可以添加更多代码,例如:


//for class
div.className = "your_class_name";
//for onclick
div.onclick = function() {destroyObject();}; // for IE

参见here了解更多

关于javascript - setAttribute 在 ie 上不起作用,有什么解决方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9529816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com