当前位置: 首页 > 图文教程 > 网络编程 > Javascript > IE浏览器的DOM模型

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 IE浏览器的DOM模型


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 518 ::
收藏到网摘: n/a

IE 处理 “/>” 形式的结尾标签有问题。如下面这段:

<form …>
<table … />
</form>

如果使用 JavaScript 向表格内添加表单元素<input>,你会发现在 IE 中<form>并没有把这些<input>包含起来。为什么呢?看看<table>元素的 innerHTML 就知道了:第一行竟然是“</form>”!可见 IE 对这种情况的处理有多糟糕。FireFox下就没有这种情况。

IE 的 DOM 模型不允许设置 <table> 元素的 innerHTML。在 DHTML 参考文档你会看到,IE 建议使用 insertRow 等方法来操作表格内容,而使用 table.innerHTML=… 在 IE 下面就会报错。 FireFox 没有这个问题。

IE 的 DOM 模型不能正确地创建单选框。如下面的 JavaScript 代码:

var radio = document.createElement(‘input’);
radio.setAttribute(‘type’, ‘radio’);
radio.setAttribute(‘name’, name);
radio.setAttribute(“value”, value);

如果把这样创建出来的单选框放到页面上,在 IE 下这些单选框都没法选中。FireFox没有这个问题。折中的解决办法是:

function createRadio(name, value) {
if (navigator.appName.indexOf(“Microsoft”) != -1) {
var radio = document.createElement(‘<input type=”radio” name=”‘ + name + ‘” />’);
radio.value = value;
return radio;
} else {
var radio = document.createElement(‘input’);
radio.setAttribute(‘type’, ‘radio’);
radio.setAttribute(‘name’, name);
radio.setAttribute(“value”, value);
return radio;
}
}