|
document.getElementById(" ") 得到的是一个对象,用 alert 显示得到的是“ object ”,而不是具体 的值,它有 value 和 length 等属性,加上 .value 得到的才 是具体的值! 参考资料: 1. document.getElementById 的用法和 DHTML.CHM 的下载地址 在网络上查找 document . getElementById 的用法,如下: A :语法:oElement = document . getElementById ( sID ) 参数:sID: 必选项。字符串 (String) 。 返回值:oElement: 对象 (Element) 。 说明: 根据指定的 id 属性值得到对象。返回 id 属性值等于 sID 的第一个对象的引用。假如对应的为一 组对象,则返回该组对象中的第一个。 如果无符合条件的对象,则返回 null 。 B :有一个例子可以很好的说明: **************************************************************************** * 这个函数中最关键的地方是 document.getElementById ,他是什么呢? * * * * 关于 document.getElementById ,是这样的: * * * * 如: document.getElementById(’hdrPageHeader_lblTitle’) * * * * 表示的意思是:获取 ID 为 :hdrPageHeader_lblTitle 的对象 * * <a >aa</a> * * <a >bb</a> * * <a >cc</a> * * <script language="javascript"> * * <!-- * * var idtext=document.getElementById(’hdrPageHeader_lblTitle’) * * alert(idtext.innerText) * * //--> * * </script> * C :另外还得到一个细节: ① document.getElementById 有时会抓 name 放过了 id ,据说是 IE 的一个 BUG ;页面中有 <input type="hidden" value="2" /> <select> 一个是用 document.getElementById 取第二个,可是,取到的却是第一个, 在 IE 中 getElementById 竟然不是先抓 id 而是先找 name 相同的物件 ... 兩個 form, 每個 form 有兩個 textbox, 兩個 form 中的 textbox 是相同的 name, 但 id 都不同 ... 這樣在 Firefox 是沒問題的 ... 但在 IE 卻只抓得到第一個出現的 name 資料 2. document 对象 http://www.phpx.com/man/dhtmlcn/objects/obj_document.html 属性: title ; bgColor ; url; ( 使用: document.title) 方法: focus 使得元素得到焦点并执行由 onfocus 事件指定的代码。 getElementById 获取对 ID 标签属性为指定值的第一个对象的引用。 getElementsByName 根据 NAME 标签属性的值获取对象的集合。 getElementsByTagName 获取基于指定元素名称的对象集合。
【2009-09-02】 【浏览601次】
上一篇:制作网页的5条非常不错的建议
下一篇:document.getElementById 和 documemt.all 的区别
|