วัตถุสคริปต์ HTML DOM
สคริปต์วัตถุ
ออบเจ็กต์สคริปต์แสดงถึงองค์ประกอบ HTML <script>
เข้าถึงวัตถุสคริปต์
คุณสามารถเข้าถึง <script> องค์ประกอบโดยใช้ getElementById():
ตัวอย่าง
var x = document.getElementById("myScript");
เคล็ดลับ:คุณยังสามารถเข้าถึงองค์ประกอบ <script> โดยใช้คอลเลกชันสคริปต์
สร้างวัตถุสคริปต์
คุณสามารถสร้าง <script> องค์ประกอบโดยใช้ document.createElement() วิธีการ:
ตัวอย่าง
var x = document.createElement("SCRIPT");
คุณสมบัติของอ็อบเจ็กต์สคริปต์
Property | Description |
---|---|
async | Sets or returns whether a script should be executed asynchronously as soon as it is available |
charset | Sets or returns the value of the charset attribute of a script |
crossOrigin | Sets or returns the the CORS settings of a script |
defer | Sets or returns whether a script should be executed when the page has finished parsing |
src | Sets or returns the value of the src attribute of a script |
text | Sets or returns the contents of all the text nodes that are children of a script |
type | Sets or returns the value of the type attribute of a script |
คุณสมบัติและเหตุการณ์มาตรฐาน
ออบเจ็กต์สคริปต์ยังสนับสนุนคุณสมบัติและเหตุการณ์ มาตรฐาน อีกด้วย
หน้าที่เกี่ยวข้อง
การอ้างอิง HTML: แท็ก HTML <script>