Đối tượng tập lệnh HTML DOM
Đối tượng tập lệnh
Đối tượng Script đại diện cho một phần tử HTML <script>.
Truy cập đố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 ():
Thí dụ
var x = document.getElementById("myScript");
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 một phần tử <script> bằng cách sử dụng phương thức document.createElement ():
Thí dụ
var x = document.createElement("SCRIPT");
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 .
Các trang liên quan
Tham chiếu HTML: Thẻ HTML <script>