当前位置: 首页 > 图文教程 > 网络编程 > Javascript > document.getElementById的一些细节

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 中的 document.getElementById的一些细节


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

① document.getElementById 有时会抓name放过了id ,据说是IE的一个BUG;
http://community.csdn.net/Expert/topic/4223/4223888.xml?temp=.1947443
页面中有
程序代码
<input type="hidden" id="hello8" name="category_id" value="2" />
<select id="category_id" onchange="al();">

一个是name="category_id" 一个是id="category_id"
用document.getElementById取第二个,可是,取到的却是第一个name=category_id
在IE中getElementById竟然不是先抓id而是先找name相同的物件...
兩個form,每個form有兩個textbox,兩個form中的textbox是相同的name,但id都不同...
這樣在Firefox是沒問題的...但在IE卻只抓得到第一個出現的name資料
下面这段代码可以验证这个结果
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]

② javascript中的getElementbyId使用
网页中的元素必须有id属性,才能通过这个方法得到,比如
<input type=text name="content" id="content">
③获取html标记主要有两种方法,一种是通过ID值,一种是通过name属性
name属性主要用于form表单内的input标记