HTMLCollection namedItem () Method
ตัวอย่าง
รับเนื้อหาขององค์ประกอบ P ด้วย ID "myElement":
function myFunction() {
var x = document.getElementsByTagName("P").namedItem("myElement");
alert(x.innerHTML);
}
ความหมายและการใช้งาน
เมธอดส่งคืน องค์ประกอบnamedItem()
ที่มี ID หรือชื่อที่ระบุใน HTMLCollection
สามารถใช้วิธีการจดชวเลขได้ และจะให้ผลลัพธ์เช่นเดียวกัน:
var x = document.getElementsByTagName("P")["myElement"];
รองรับเบราว์เซอร์
Method | |||||
---|---|---|---|---|---|
namedItem() | Yes | Yes | Yes | Yes | Yes |
ไวยากรณ์
HTMLCollection.namedItem(name)
หรือ:
HTMLCollection[name]
ค่าพารามิเตอร์
Parameter | Description |
---|---|
name | Required. The value of the id attribute, or name attribute, of the element you want to return. |
คืนมูลค่า
อ อบเจ็กต์ Elementแสดงถึงองค์ประกอบที่ มี ID หรือชื่อที่ระบุ
ส่งคืนค่า nullหากองค์ประกอบไม่มีอยู่
หน้าที่เกี่ยวข้อง
HTMLCollection: item() Method
HTMLCollection: คุณสมบัติlength