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

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 document.getElementById的一些细节


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 224 ::
收藏到网摘: 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标记