1.getElementById
作用:一般頁(yè)面里ID是唯一的,用于準(zhǔn)備定為一個(gè)元素
語(yǔ)法: document.getElementById(id)
參數(shù):id :必選項(xiàng)為字符串(String)
返回值:對(duì)象; 返回相同id對(duì)象中的第一個(gè),按在頁(yè)面中出現(xiàn)的次序,如果無(wú)符合條件的對(duì)象,則返回 null
- example:document.getElementById("id1").value;
example:document.getElementById("id1").value;
2.getElementsByName
作用:按元素的名稱查找,返回一個(gè)同名元素的數(shù)組
語(yǔ)法: document.getElementsByName(name)
參數(shù):name :必選項(xiàng)為字符串(String)
返回值:數(shù)組對(duì)象; 如果無(wú)符合條件的對(duì)象,則返回空數(shù)組,按在頁(yè)面中出現(xiàn)的次序
- example:document.getElementsByName("name1")[0].value;
- document.getElementsByName("name1")[1].value;
example:document.getElementsByName("name1")[0].value;
document.getElementsByName("name1")[1].value;
3.getElementsByTagName
作用:按HTML標(biāo)簽名查詢,返回一個(gè)相同標(biāo)簽元素的數(shù)組
語(yǔ)法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
參數(shù):tagname:必選項(xiàng)為字符串(String),根據(jù)HTML標(biāo)簽檢索。
返回值:數(shù)組對(duì)象; 如果無(wú)符合條件的對(duì)象,則返回空數(shù)組,按在頁(yè)面中出現(xiàn)的次序
- example:document.getElementsByTagName("p")[0].childNodes[0].nodeValue;
- document.getElementsByTagName("p")[1].childNodes[0].nodeValue
posted on 2008-11-24 23:57
Vincent-chen 閱讀(193)
評(píng)論(0) 編輯 收藏 所屬分類:
JavaScript