当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 动态修改DOM 里面的 id 属性的弊端分析

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 中的 动态修改DOM 里面的 id 属性的弊端分析


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

我不知道是否有什么标准规定不允许修改id属性,或者不建议修改id属性,总之IE对此支持不佳。 在IE当中,修改id属性对将来的DOM操作没什么不符合标准的影响,你仍然可以通过document.getElementById()找到该元素,然后在CSS支持上就有问题了,id修改后并不会自动去重新匹配CSS规则,因此id修改后不会体现出应有的样式。
因此,进行DOM编程时应该避免修改id属性,如果需要动态改变匹配的CSS规则,就改变class属性吧。我碰到这个问题时也就是尝试通过修改id属性修改唯一匹配某个CSS过滤器的元素,结果发现修改后在IE中完全没有修改,之后改为用class属性实现同样的目的。