1.getElementById
作用:一般頁面里ID是唯一的,用于準備定為一個元素
語法: document.getElementById(id)
參數(shù):id :必選項為字符串(String)
返回值:對象; 返回相同id對象中的第一個,按在頁面中出現(xiàn)的次序,如果無符合條件的對象,則返回 null
- example:document.getElementById("id1").value;
example:document.getElementById("id1").value;
2.getElementsByName
作用:按元素的名稱查找,返回一個同名元素的數(shù)組
語法: document.getElementsByName(name)
參數(shù):name :必選項為字符串(String)
返回值:數(shù)組對象; 如果無符合條件的對象,則返回空數(shù)組,按在頁面中出現(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標簽名查詢,返回一個相同標簽元素的數(shù)組
語法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
參數(shù):tagname:必選項為字符串(String),根據(jù)HTML標簽檢索。
返回值:數(shù)組對象; 如果無符合條件的對象,則返回空數(shù)組,按在頁面中出現(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)
評論(0) 編輯 收藏 所屬分類:
JavaScript