Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

คุณสมบัติเอกสาร (Document Properties) ของ IE4 DOM Method

IE4 DOM (Internet Explorer 4 Document Object Model) มีคุณสมบัติเอกสารเฉพาะตัวที่แตกต่างจาก W3C DOM ด้านล่างคือรายการหลัก:

ตารางคุณสมบัติ Document ของ IE4 DOM

#Propertyคำอธิบายตัวอย่าง
1activeElementอ่านอย่างเดียว (Read-only) อ้างอิง Element ที่กำลังมี Focus อยู่ (Input, Button, Link, ฯลฯ)document.activeElement
2all[]อาร์เรย์ (Collection) ของ Element ทุกตัวในเอกสาร เข้าถึงได้ด้วย Index, ID, หรือ Namedocument.all[0], document.all["myId"], document.all.myName
3charsetCharacter Set ของเอกสาร (Read/Write)document.charset = "UTF-8"
4children[]อาร์เรย์ของ HTML Elements ที่เป็น Direct Children ของ Document (ไม่รวม Text Nodes, Comments) - ต่างจาก all[] ที่รวมทุกอย่างdocument.children[0] (มักเป็น <html>)
5defaultCharsetDefault Character Set ของเอกสาร (Read-only)document.defaultCharset
6expandoBoolean: true=อนุญาตให้เพิ่ม Property ใหม่บน Client-side Objects, false=ห้าม (Default: true)document.expando = false
7parentWindowอ้างอิง Window Object ที่มี Document นี้ (IE Specific)document.parentWindow
8selectionออบเจกต์ Selection สำหรับจัดการข้อความที่เลือก (TextRange)document.selection.createRange()
9styleSheets[]คอลเลกชัน StyleSheet Objects ในเอกสารdocument.styleSheets[0]
10urlURL ของเอกสาร (Read-only) - เทียบเท่า document.URL ใน W3Cdocument.url
11referrerURL ของหน้าที่เชื่อมต่อมา (Read-only)document.referrer
12domainDomain ของเอกสาร (ใช้สำหรับ Cross-frame Scripting) - สามารถตั้งค่าได้ (Relaxing)document.domain = "example.com"
13cookieString: อ่าน/เขียน Cookie ของเอกสารdocument.cookie = "name=value"

เมธอด (Methods) ที่เกี่ยวข้อง

  • document.all.tags(tagName) - คืน Collection ของ Element ตาม Tag Name
  • document.all.item(name, index) - เข้าถึง Element ใน Collection
  • document.recalc() - บังคับคำนวณ Expression ใหม่ (IE Specific)
  • document.createStyleSheet() - สร้าง StyleSheet ใหม่

การเข้าถึง Element ย่อย (Element Properties/Methods ใน IE4)

  • element.innerHTML / outerHTML - เนื้อหา HTML (IE พัฒนาเอง ก่อนเป็นมาตรฐาน)
  • element.innerText / outerText - เนื้อหา Text (IE Specific, W3C ใช้ textContent)
  • element.insertAdjacentHTML(position, html) - แทรก HTML (BeforeBegin, AfterBegin, BeforeEnd, AfterEnd)
  • element.contains(otherElement) - ตรวจสอบว่าเป็น Ancestor หรือไม่
  • element.sourceIndex - Index ใน document.all

สถานะปัจจุบัน

  • ส่วนใหญ่ (activeElement, children, styleSheets, url, referrer, domain, cookie, innerHTML, insertAdjacentHTML, contains) **กลายเป็นมาตรฐาน W3C/DOM Living Standard** แล้ว
  • document.all, document.all.tags(), innerText, sourceIndex, parentWindow, selection (TextRange) **ยังคงเป็น IE-Specific / Legacy**
  • ไม่ควรใช้ในโค้ดใหม่ ใช้ W3C DOM Standard Methods แทน