为什么document.getElementById('tableId')。innerHTML在IE8中不起作用? [英] Why is document.getElementById('tableId').innerHTML not working in IE8?

查看:290
本文介绍了为什么document.getElementById('tableId')。innerHTML在IE8中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面中使用Java Script修改 document.getElementById('')。innerHTML 。它在Firefox中正常工作,但不是IE8。请参阅下面的详细信息:

I modify document.getElementById('').innerHTML with Java Script in a page. It's working fine in Firefox, but not IE8. Please see below for more details:

HTML代码:

<table>
  <tr id="abc">
     <td id="ccc" style="color:red;">ccc</td>
  </tr>
</table>

Java脚本代码:

  document.getElementById('abc').innerHTML = '<td id="bbc" style="color:yellow;">abc</td>'

当我在Firefox中运行JS代码时,会将显示单词从ccc更改为abc,但它不是在IE8工作,有没有人知道为什么?有没有什么办法可以使IE8工作?

When I run the JS code in Firefox, it will change the display word from 'ccc' to 'abc', but it's just not working in IE8, does anyone know why? Is there any way I can make this work in IE8 as well?

推荐答案

由于问题在于IE8,请参阅MSDN

Since the problem is in IE8, see MSDN:


属性是除以下所有对象的所有对象的读/写,它是只读的:COL,COLGROUP,FRAMESET,HEAD,HTML,STYLE,TABLE,TBODY,TFOOT,THEAD,TITLE, TR

(强调我的)

Colin的解决方法(设置<$ c cd> c $ c> innerText 而不是 innerHTML > tr )在你的情况下是一个好的。如果您的需求变得更加复杂,您将不得不诉诸于表对象模型

Colin's work-around (setting innerText on the td instead of innerHTML on the tr) is a good one in your case. If your needs become more complex, you'll have to resort to The Table Object Model.

这篇关于为什么document.getElementById('tableId')。innerHTML在IE8中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆