Đối tượng tập lệnh HTML DOM
Đối tượng tập lệnh
Đối tượng Script đại diện cho phần tử HTML <script>.
Truy cập một đối tượng tập lệnh
Bạn có thể truy cập phần tử <script> bằng cách sử dụng getElementById():
Mẹo: Bạn cũng có thể truy cập phần tử <script> bằng cách sử dụng bộ sưu tập tập lệnh .
Tạo một đối tượng tập lệnh
Bạn có thể tạo phần tử <script> bằng cách sử dụng phương thức document.createElement():
Thuộc tính đối tượng tập lệnh
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 |
Thuộc tính và sự kiện tiêu chuẩn
Đối tượng Script cũng hỗ trợ các thuộc tính và sự kiện tiêu chuẩn.
Trang liên quan
Tham chiếu HTML: Thẻ HTML <script>