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 :
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也不能赋值,
<!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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
CentOS 7.2下MySQL的安装与相关配置
浅谈 Mousewheel 事件
flash与asp/php/asp.net通信的方法第1/3页
Asp定时执行操作、各种网页定时操作详解
基于mysql乐观锁实现秒杀的示例代码
![](https://img.aspxhome.com/file/2023/2/74852_0s.png)
用css制作星级投票评分功能
![](https://img.aspxhome.com/file/UploadPic/20071/2007131101422899s.gif)
python中Tkinter复选框Checkbutton是否被选中判断
![](https://img.aspxhome.com/file/2023/0/118790_0s.png)
golang 函数以及函数和方法的详解及区别
![](https://img.aspxhome.com/file/2023/6/112226_0s.jpg)
序列化Python对象的方法
浅析python标准库中的glob
Thinkphp5.0 框架使用模型Model添加、更新、删除数据操作详解
实战mysql导出中文乱码及phpmyadmin导入中文乱码的解决方法
![](https://img.aspxhome.com/file/2023/0/126310_0s.jpg)
用Python编写简单的定时器的方法
python虚拟环境的安装配置图文教程
![](https://img.aspxhome.com/file/2023/1/131251_0s.png)
MySQL数据库的触发器的使用
Django使用mysqlclient服务连接并写入数据库的操作过程
![](https://img.aspxhome.com/file/2023/5/95525_0s.png)
python获取文件路径、文件名、后缀名的实例
使用python 爬虫抓站的一些技巧总结
![](https://img.aspxhome.com/file/2023/2/117352_0s.jpg)
Mybatis-Plus读写Mysql的Json字段的操作代码
![](https://img.aspxhome.com/file/2023/1/71241_0s.png)