简体   繁体   English

IE无法将对象的innerHTML设置为空

[英]IE can't set innerHTML of object to empty

Hello i have such problem, i need to make empty some of my elements in document, when i am trying to do this in IE 11 it fails with error Unknown runtime error on 3rd line. 您好,我有这样的问题,我需要在文档中清空一些元素,当我尝试在IE 11中这样做时,它会失败,并在第三行出现错误Unknown runtime error
js js

var element = document.getElementById('sum');
alert(element.innerHTML);
element.innerHTML = '';

and html 和html

<table>
<thead></thead>
<tbody id="sum">
</tbody>
</table>

In alert i see <TBODY></TBODY> . 在警报中,我看到<TBODY></TBODY> This code works in google chrome and firefox, but not in IE, how i can fix this problem? 此代码可在谷歌浏览器和Firefox中使用,但不适用于IE,我该如何解决此问题?
Thank you for help. 谢谢你的帮助。

The innerHTML property has some problems in IE when trying to add or update form elements, the workaround is to create a div and set the innerHtml property on that before appending to the DOM: 尝试添加或更新表单元素时,innerHTML属性在IE中存在一些问题,解决方法是在添加到DOM之前创建一个div并在其上设置innerHtml属性:

var newdiv = document.createElement("div");
newdiv.innerHTML = xmlhttp.responseText;
var container = document.getElementById(id);
container.appendChild(newdiv);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM