【转】IE6/7/8/9中Table/Select的innerHTML赋值会报错

IE6/7/8/9中Table/Select的innerHTML赋值会报错,如下

01<!DOCTYPE HTML>
02 <html>
03 <head>
04 <meta charset="utf-8">
05 <title>IE6/7/8/9中TABLE的innerHTML不能赋值</title>
06 </head>
07 <body>
08 <script type="text/javascript">
09try{
10var table = document.createElement('table');
11 table.innerHTML = '<tr><td>Test <FONT style="BACKGROUND-COLOR: #00ffff">table innerHTML</FONT></td></tr>'
12document.body.appendChild(table);
13}catch(e){
14alert(e);
15}
16 </script>
17 </body>
18 </html>

IE6/7 :

IE8 :

IE9 :


Firefox/Safari/Chrome/Opera中正常。Ext.DomHelper中使用div,把table添加到div中间接实现。

MSDN 写道

The property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR. The property has no default value.
DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are not supported in IE8 mode. For more information, see About Dynamic Properties.


Select元素的innerHTML也不能赋值,
01<!DOCTYPE HTML>
02 <html>
03 <head>
04 <meta charset="utf-8">
05 <title>IE6/7/8/9中Select的innerHTML不能赋值</title>
06 </head>
07 <body>
08 <script type="text/javascript">
09try{
10var select = document.createElement("select");
11 select.innerHTML = '<option value="1">one</option>';
12document.body.appendChild(select);
13}catch(e){
14alert(e);
15}
16 </script>
17 </body>
18 </html>

但不抛异常。


相关:
http://msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx
https://developer.mozilla.org/en/dom:element.innerhtml
http://www.w3.org/TR/html5/apis-in-html-documents.html#dom-innerhtml

 

 

转至:http://www.cnblogs.com/snandy/archive/2011/04/04/2005167.html

<script type="text/javascript"></script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值