JS 使用DOM访问网页元素的示例
内容摘要
这篇文章主要为大家详细介绍了JS 使用DOM访问网页元素的示例,具有一定的参考价值,可以用来参考一下。
Firefox以及其他Gecko引擎的浏览器遇到的最常见的兼容性问题是IE DHTML
Firefox以及其他Gecko引擎的浏览器遇到的最常见的兼容性问题是IE DHTML
文章正文
这篇文章主要为大家详细介绍了JS 使用DOM访问网页元素的示例,具有一定的参考价值,可以用来参考一下。
Firefox以及其他Gecko引擎的浏览器遇到的最常见的兼容性问题是IE DHTML和W3C DOM的区别。不规范的DHTML脚本中最容易犯的一个错误就是使用不规范的方式来访问网页元素。我们曾经用spider爬一些国内著名门户网站,单从数量上看,95%以上的javascript错误都来自于此。常见的访问网页元素的不规范方式有一下几种:
1. 直接用id或name属性名访问网页元素,例如:1 2 3 4 5 | <code class = "js" > <div id= "icefable1" >...</div> <script language= "javascript" > icefable1.style.width=0; </script></code> |
1 2 3 4 5 6 7 | <code class = "js" > <div id= "icefable1" >...</div> <script language= "javascript" > document.getElementById( "icefable1" ).style.width=0; </script> // 来自:php教程(www.idcnote.com) </code> |
1 2 3 4 5 6 7 8 9 10 11 | <code class = "js" > <td width= "33%" class =tab-on id=navcell onm ouseover=switchCell(0)><div align= "center" >重要提示</div></td> <td width= "33%" class =tab-off id=navcell onm ouseover=switchCell(1)><div align= "center" >学术活动</div></td> <td width= "34%" class =tab-off id=navcell onm ouseover=switchCell(2)><div align= "center" >交大热点</div></td> ... <script language= "javascript" > ... navcell[n].className= "tab-on" ; ... </script> // 来自:php教程(www.idcnote.com) </code> |
1 2 3 4 5 6 7 8 9 10 11 | <code class = "js" > <td width= "33%" class =tab-on id= "navcell1" onm ouseover=switchCell(0)><div align= "center" >重要提示</div></td> <td width= "33%" class =tab-off id= "navcell2" onm ouseover=switchCell(1)><div align= "center" >学术活动</div></td> <td width= "34%" class =tab-off id= "navcell3" onm ouseover=switchCell(2)><div align= "center" >交大热点</div></td> ... <script language= "javascript" > ... eval ( 'document.getElementById("navcell' +n+ '").className="tab-on"' ); ... </script> // 来自:php教程(www.idcnote.com) </code> |
1 2 3 4 5 | <code class = "js" > <HTMLelement>.all.<id或name> <HTMLelement>.all( "<id或name>" ) <HTMLelement>.all[ "<id或name>" ] // 来自:php教程(www.idcnote.com) </code> |
注:关于JS 使用DOM访问网页元素的示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释