欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

沒有document.getElementByName方法

 更新時(shí)間:2013年08月19日 18:02:29   作者:  
document.getElementByName方法沒有document.getElementsByName得到的是標(biāo)簽的數(shù)組,下面為大家詳細(xì)介紹下具體的使用,感興趣的朋友可以參考下,希望對大家有所幫助
首先聲明的是:
document.getElementByName方法沒有。document.getElementsByName得到的是標(biāo)簽的數(shù)組
document.getElementId得到的是某一個(gè)標(biāo)簽
<form name="form_write">
<input name="content" type="text">

然而可以用很淺顯的方式得到如:

var fn = document.getElementsByName("form_write")[0]; //得到這個(gè)form下的對象
fn.content.value;//就直接去用這個(gè)對象取值就可以了。
document.getElementById 1、getElementById

作用:一般頁面里ID是唯一的,用于準(zhǔn)備定位一個(gè)元素
語法: document.getElementById(id)
參數(shù):id :必選項(xiàng)為字符串(String)
返回值:對象; 返回相同id對象中的第一個(gè),按在頁面中出現(xiàn)的次序,如果無符合條件的對象,則返回 null

example:
復(fù)制代碼 代碼如下:

document.getElementById("id1").value;


2、getElementsByName

作用:按元素的名稱查找,返回一個(gè)同名元素的數(shù)組
語法: document.getElementsByName(name)
參數(shù):name :必選項(xiàng)為字符串(String)
返回值:數(shù)組對象; 如果無符合條件的對象,則返回空數(shù)組,按在頁面中出現(xiàn)的次序
注意:返回?cái)?shù)組值為value屬性的值,
如果某標(biāo)簽無value屬性,當(dāng)你添加上value屬性并賦值后,getElementsByName也能取到其值,
當(dāng)未對value屬性賦值時(shí), getElementsByName返回?cái)?shù)組值將是undefined ,
但仍能獲得相同name標(biāo)簽的個(gè)數(shù)document.getElementsByName(name).length
當(dāng)未設(shè)置name屬性時(shí)document.getElementsByName仍能使用,它將根據(jù)你id取得value屬性的值

example:
復(fù)制代碼 代碼如下:

document.getElementsByName("name1")[0].value;
document.getElementsByName("name1")[1].value;
<span id='CBylawIndexName' class='normalNode' value='all' >全部</span>"
<span id='CBylawIndexName' class='normalNode' value='ALL' >全部</span>"

span標(biāo)簽其實(shí)沒有name和value屬性
但document.getElementsByName("CBylawIndexName")仍將取得value的值

3、getElementsByTagName

作用:按HTML標(biāo)簽名查詢,返回一個(gè)相同標(biāo)簽元素的數(shù)組
語法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
參數(shù):tagname:必選項(xiàng)為字符串(String),根據(jù)HTML標(biāo)簽檢索。
返回值:數(shù)組對象; 如果無符合條件的對象,則返回空數(shù)組,按在頁面中出現(xiàn)的次序

example:
復(fù)制代碼 代碼如下:

document.getElementsByTagName("p")[0].childNodes[0].nodeValue;
document.getElementsByTagName("p")[1].childNodes[0].nodeValue;

相關(guān)文章

最新評論