This HTML tutorial explains how to use the HTML element called the tag with syntax and examples.
Sự miêu tả
The HTML tag is used to embed or reference a client-side script such as JavaScript. This tag is also commonly referred to as the element.
cú pháp
There are two ways that you can use the tag. You can either embed the code within the tags or you can reference a file that includes the code.
Mã nhúng
In HTML, the syntax for the tag that has embedded code within the tag is:
document.write["HTML5 Script Tag Example"];
Tham khảo một tập tin
In HTML, the syntax for the tag that references a javascript file is:
Thuộc tính
In addition to the Global Attributes, the following is a list of attributes that are specific to the tag:
Thuộc tínhMô tảKhả năng tương thíchHTMLasyncGiá trị Boolean để cho biết liệu trình duyệt có nên thực thi tập lệnh không đồng bộHTML5srcURI của tập lệnh bên ngoàiHTML 4. 01, HTML5typeNgôn ngữ kịch bản của mã. Nó có thể là một trong các giá trị sau
- văn bản/javascript
- văn bản/ecmascript
- ứng dụng/javascript
- ứng dụng/ecmascript
Ghi chú
- The HTML element is found either within the tag or the tag.
- See also tag.
tính tương thích của trình duyệt web
The tag has basic support with the following browsers:
- Trình duyệt Chrome
- Android
- Firefox [Tắc kè]
- Firefox Di động [Tắc kè]
- Internet Explorer [IE]
- Cạnh di động
- Ô-pê-ra
- Opera di động
- Safari [WebKit]
- Safari di động
Ví dụ
We will discuss the tag below, exploring examples of how to use the tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.
- HTML5
- HTML4
- XHTML
Tài liệu HTML5
If you created a new web page in HTML5, your tag might look like this:
HTML5 Example by www.techonthenet.com
document.write["HTML5 Script Tag Example"];
In this HTML5 Document example, we have used the tag within the tag to reference a javascript file called functions.js. We have also used the tag within the tag to print the text "HTML5 Script Tag Example".
Notice that in the HTML5 Document example that type="text/javascript"
is not required in the tag.
HTML4. 01 Văn bản chuyển tiếp
If you created a new web page in HTML 4.01 Transitional, your tag might look like this:
HTML 4.01 Transitional Example by www.techonthenet.com
document.write["HTML 4.01 Transitional Script Tag Example"];
In this HTML 4.01 Transitional Document example, we have used the tag within the tag to reference a javascript file called functions.js. We have also used the tag within the tag to print the text "HTML 4.01 Transitional Script Tag Example".
XHTML 1. 0 Tài liệu chuyển tiếp
If you created a new web page in XHTML 1.0 Transitional, your tag might look like this:
XHMTL 1.0 Transitional Example by www.techonthenet.com
document.write["HTML XHTML 1.0 Transitional Script Tag Example"];
In this XHTML 1.0 Transitional Document example, we have used the tag within the tag to reference a javascript file called functions.js. We have also used the tag within the tag to print the text "XHTML 1.0 Transitional Script Tag Example".
XHTML 1. 0 Tài liệu nghiêm ngặt
If you created a new web page in XHTML 1.0 Strict, your tag might look like this:
XHTML 1.0 Strict Example by www.techonthenet.com
document.write["HTML XHTML 1.0 Strict Script Tag Example"];
In this XHTML 1.0 Strict Document example, we have used the tag within the tag to reference a javascript file called functions.js. We have also used the tag within the tag to print the text "XHTML 1.0 Strict Script Tag Example".
XHTML 1. 1 tài liệu
If you created a new web page in XHTML 1.1, your tag might look like this:
XHTML 1.1 Example by www.techonthenet.com
document.write["HTML XHTML 1.1 Script Tag Example"];
Trong XHTML 1 này. 1 Ví dụ về tài liệu, chúng tôi đã sử dụng thẻ trong thẻ để tham chiếu tệp javascript có tên là hàm. js. Chúng tôi cũng đã sử dụng thẻ trong thẻ để in văn bản "XHTML 1. 1 Ví dụ về thẻ tập lệnh"