Cú pháp chính xác của thẻ script trong HTML là gì?

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
HTML4. 01 [Không bắt buộc trong HTML5]ngôn ngữngôn ngữ kịch bản. Sử dụng loại thay thế. Deprecateddefer Giá trị Boolean để cho biết liệu tập lệnh có được thực thi sau khi tài liệu đã được phân tích cú phápHTML 4. 01, HTML5

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"

Lệnh script trong HTML là gì?

Thẻ dùng để nhúng tập lệnh phía máy khách [JavaScript] . Phần tử

Thẻ script trong HTML ở đâu?

Tập lệnh có thể được đặt trong , or in the section of an HTML page, or in both .

Làm thế nào để viết một tập lệnh HTML?

Trình chỉnh sửa HTML .
Bước 1. Mở Notepad [PC] Windows 8 trở lên. .
Bước 1. Mở TextEdit [Mac] Mở Finder > Ứng dụng > TextEdit. .
Bước 2. Viết một số HTML. Viết hoặc sao chép mã HTML sau vào Notepad. .
Bước 3. Lưu trang HTML. Lưu tệp trên máy tính của bạn. .
Bước 4. Xem trang HTML trong trình duyệt của bạn

Đó là cú pháp chính xác để sử dụng tệp JavaScript?

Để bao gồm một tệp JavaScript bên ngoài, chúng ta có thể sử dụng thẻ script với thuộc tính src . Bạn đã sử dụng thuộc tính src khi sử dụng hình ảnh. Giá trị cho thuộc tính src phải là đường dẫn đến tệp JavaScript của bạn. Thẻ tập lệnh này phải được bao gồm giữa các thẻ

Chủ Đề