IE6/7/8/9中Table/Select的innerHTML不能赋值的解决方法

时间:2024-04-10 16:16:48 

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

<!DOCTYPE HTML> <html> <head> <meta charset="gb2312"> <title>IE6/7/8/9中TABLE的innerHTML不能赋值</title> </head> <body> <script type="text/javascript"> try{ var table = document.createElement('table'); table.innerHTML = '<tr><td>Test table innerHTML</td></tr>' document.body.appendChild(table); }catch(e){ alert(e); } </script> </body> </html>



IE6/7 :

IE6/7/8/9中Table/Select的innerHTML不能赋值的解决方法

IE8 :

IE6/7/8/9中Table/Select的innerHTML不能赋值的解决方法

IE9 :

IE6/7/8/9中Table/Select的innerHTML不能赋值的解决方法


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也不能赋值,

<!DOCTYPE HTML> <html> <head> <meta charset="gb2312"> <title>IE6/7/8/9中Select的innerHTML不能赋值</title> </head> <body> <script type="text/javascript"> try{ var select = document.createElement("select"); select.innerHTML = '<option value="1">one</option>'; document.body.appendChild(select); }catch(e){ alert(e); } </script> </body> </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

标签:Select,innerHTML,不能赋值
0
投稿

猜你喜欢

  • CentOS 7.2下MySQL的安装与相关配置

    2024-01-16 23:21:29
  • 浅谈 Mousewheel 事件

    2010-08-16 12:37:00
  • flash与asp/php/asp.net通信的方法第1/3页

    2023-11-15 03:43:03
  • Asp定时执行操作、各种网页定时操作详解

    2008-06-10 17:32:00
  • 基于mysql乐观锁实现秒杀的示例代码

    2024-01-18 02:01:41
  • 用css制作星级投票评分功能

    2008-01-08 21:12:00
  • python中Tkinter复选框Checkbutton是否被选中判断

    2023-10-20 16:41:19
  • golang 函数以及函数和方法的详解及区别

    2024-02-16 22:33:03
  • 序列化Python对象的方法

    2022-07-09 22:51:59
  • 浅析python标准库中的glob

    2023-08-04 02:39:10
  • Thinkphp5.0 框架使用模型Model添加、更新、删除数据操作详解

    2024-06-07 15:35:37
  • 实战mysql导出中文乱码及phpmyadmin导入中文乱码的解决方法

    2024-05-11 09:19:05
  • 用Python编写简单的定时器的方法

    2022-03-15 07:20:32
  • python虚拟环境的安装配置图文教程

    2023-09-23 09:03:04
  • MySQL数据库的触发器的使用

    2024-01-19 07:17:37
  • Django使用mysqlclient服务连接并写入数据库的操作过程

    2024-01-27 14:55:39
  • python获取文件路径、文件名、后缀名的实例

    2022-05-05 10:47:27
  • 使用python 爬虫抓站的一些技巧总结

    2021-01-02 07:35:57
  • Mybatis-Plus读写Mysql的Json字段的操作代码

    2024-01-15 15:34:29
  • CentOS 7安装MySQL的详细步骤

    2024-01-25 19:59:17
  • asp之家 网络编程 m.aspxhome.com