getElementById Method  Internet Development Index --------------------------------------------------------------------------------Returns a reference to the first object with the specified value of the ID attribute.SyntaxoElement = document.getElementById(sIDValue)
ParameterssIDValue Required. String that specifies the value of an ID attribute. Return ValueReturns the first object with the same ID attribute as the specified value.ResIf the ID value belongs to a collection, the getElementById method returns the first object in the collection.ExampleThis example uses the getElementById method to return the first occurrence of the ID attribute value, oDiv.HideExample<SCRIPT>
function fnGetId(){
// Returns the first DIV element in the collection.
var oVDiv=document.getElementById("oDiv1");
}
</SCRIPT>
<DIV ID="oDiv1">Div #1</DIV>
<DIV ID="oDiv2">Div #2</DIV>
<DIV ID="oDiv3">Div #3</DIV>
<INPUT TYPE="button" VALUE="Get Names" onclick="fnGetId()">
Standards InformationThis method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 . Applies To[ Object Name ] 
Platform Version 
Win16:  
Win32:  
Unix:  
Mac:  
Windows CE:  
Version data is listed when the mouse hovers over a link, or the link has focus. 
 document 
Move the mouse pointer over an element in the Applies To list to display availability information for the listed platforms. 

解决方案 »

  1.   

    最近為了讓網頁在 IE 與 Firefox都可以正常執行,
    所以改了許多javascript,
    其中,Firefox最常出現的就是getElementById的問題,
    在IE中,之前是習慣在驗證表單的時候直接使用form的名稱去取得下面的表單元件,
    例如 : if (frm.tbxuid.value = ""){
    alert("請輸入帳號");
    } 但是,這樣的語法在firefox是不能跑的,
    所以需要改用getElementById去取得物件,
    可是,要使用getElementById的前提是表單的物件都需要有id的屬性內容,
    偏偏,之前沒有加ID的習慣...
    後來硬是將許多物件都加上了ID後發現...radio跟checkbox有問題...
    因為radio跟checkbox的name都是一樣的,
    但是id不能設定都是一樣的,(參考網址 : 細說HTML元素的ID和Name屬性的區別)
    所以,radio跟checkbox要用getElementsByName來抓,
    在使用getElementById時我是想說應該有ByName的但是測試了getElementByName,
    發覺沒有用...後來看了上面那篇文章才發現原來是少了個s (getElementByName 應該為 getElementsByName),
    後來還試了一下看看用getElementsByName抓不抓的到text或是areatext等資料,
    結果發現是抓不到的,所以還是硬著頭皮將表元件一個一個檢查了...所以像上面的程式就要改成if (document.getElementById('tbxuid').value = ""){
    alert("請輸入帳號");
    } 要讓所有的瀏覽器都可瀏覽還真是不容易啊...除非網頁的內容很單純....
      

  2.   

    改为:
     document.getElementById ("myt").style.display='none';  display是样式的一个属性,不是这个table的属性,所以需要加style。
      所以你的getElementById用得没错 :)
      这些东西知道去msdn查就可以了:
      http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/execcommand.asp