getElmentById的本身的含义是?
具体用法到底有哪些?

解决方案 »

  1.   

    document.getElementById(" ") 得到的是一个对象,用 alert 显示得到的是 “ object ”,而不是具体的值,它有 value 和 length 等属性,加上 .value 得到的才 是具体的值! 今天在网络上查找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 id="hdrPageHeader_lblTitle0">aa</a>                             *
      * <a id="hdrPageHeader_lblTitle">bb</a>                              *
      * <a id="hdrPageHeader_lblTitle1">cc</a>                             *
      * <script language="javascript">                                     *
      * <!--                                                               *
      * var idtext=document.getElementById('hdrPageHeader_lblTitle')       *
      * alert(idtext.innerText)                                            *
      * //-->                                                              *
      * </script>                                                          *
      *                                                                          *
      **************************************************************************** C:另外还得到一个细节:
    http://bbs.cnitn.cn/dispbbs.asp?boardid=20&id=12957,内容是:
    ① 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資料
    D:在得到答案后,同时也得到了两本好的手册工具,1.DHTML.CHM -----很全面的DHTML的参考手册2.javascript的参考手册饮水思源,我还是不要把别人的成果直接放到这里,下面这个地址提供了下载连接:
    http://www.xy72.com/bbs/dispbbs.asp?boardID=11&ID=71&page=1
      

  2.   


    语法:
    oElement = document . getElementById ( sID ) 
    参数:
    sID  : 必选项。字符串(String)。 返回值:
    oElement  : 对象(Element)。 说明:
    根据指定的 id 属性值得到对象。返回 id 属性值等于 sID 的第一个对象的引用。假如对应的为一组对象,则返回该组对象中的第一个。 
    如果无符合条件的对象,则返回 null 。 
    应用于:
    IE5.0+ document <script>
    function rdl_doCheck(e){
    var oCheckboxs=document.getElementsByTagName("input");
    for (n=0;n<oCheckboxs.length;n++) oCheckboxs[n].checked=false;
    with (document.all("oSelect")) {
    var sValue=options[selectedIndex].value;
    }
    if (document.getElementById(sValue)!=null) document.getElementById(sValue).checked=true;
    }
    </script>
    <input type=checkbox id=First><label for=First>我的ID是<b>First</b></label><br>
    <input type=checkbox id=First><label for=First>我的ID也是<b>First</b></label><br>
    <input type=checkbox id=Second><label for=Second>我的ID是<b>Second</b></label><br><br>
    <select style="width:200px;" onchange="rdl_doCheck();" id=oSelect>
    <option value="none" selected style="text-align:center;color:#333333;">--请选择--</option>
    <option value="First">getElementById("First")</option>
    <option value="Second">getElementById("Second")</option>
    </select>
      

  3.   

    同意楼上的
    document.getElementById(sID)是根据某个标签的属性ID去获得该对象。
      

  4.   


    高手們順便幫我看一下這個問題怎解決 
    http://topic.csdn.net/u/20071024/21/2368ffaa-9a54-48f3-8f86-95ad2e0138bd.html