id name tagname

來源:互聯網
上載者:User

標籤:var   指定   get   屬性查詢   bsp   document   而不是   nts   內容   

getElementById()                         返回帶有指定id的節點對象的集合。

 

getElementsByName()                   返回帶有指定名稱的節點對象的集合。 

與getElementById() 方法不同的是,通過元素的 name 屬性查詢元素,而不是通過 id 屬性。

 

getElementsByTagName()        返回帶有指定標籤名的節點對象的集合。返回元素的順序是它們在文檔中的順序

是標籤的名稱,如p、a、img等標籤名。

 

<script>function mz(){  var x=document.getElementsByName("xx1");    alert(x.length);}//結果是彈出1function bq(){  var x=document.getElementsByTagName("input");    alert(x.length);  }//結果是彈出2</script><body><input type="textarea" name="x1" id="x2">  <input type="textarea" name="xx1" id="xx2"> <br /><button onclick="mz()"/>看看name有幾項?</button><button onclick="bq()"/>看看標籤有幾項?</button></body>

 

 

getAttribute()                         通過元素節點的屬性名稱擷取屬性的值。

標籤的名稱,如p、a、img等標籤名,獲得他們的id或title

 

setAttribute()                         增加一個指定名稱和值的新屬性,或者把一個現有的屬性設定為指定的值。

括弧裡:(“要改的屬性名稱”,“要改的內容”)

 

 

 

id name tagname

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.