From d192fb918b0e2aa8869de6dcc59de8464b6e879a Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Fri, 11 Dec 2020 18:59:39 -0500 Subject: dump 2020-12-11 --- files/zh-tw/web/html/element/script/index.html | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'files/zh-tw/web/html/element/script') diff --git a/files/zh-tw/web/html/element/script/index.html b/files/zh-tw/web/html/element/script/index.html index 575be45b12..3b78b80a41 100644 --- a/files/zh-tw/web/html/element/script/index.html +++ b/files/zh-tw/web/html/element/script/index.html @@ -59,16 +59,22 @@ translation_of: Web/HTML/Element/script
{{htmlattrdef("crossorigin")}}
針對沒有通過標準 CORS 的一般 script 元素,會把最少的資訊傳給 {{domxref('GlobalEventHandlers.onerror', 'window.onerror')}}。若要允許另一個域名站點的靜態內容,列出錯誤訊息,請使用此屬性。請參見 CORS settings attributes 以以取得對其有效參數的,更具描述性的解釋。
{{htmlattrdef("defer")}}
-
This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firing {{event("DOMContentLoaded")}}.
-
Scripts with the defer attribute will prevent the DOMContentLoaded event from firing until the script has loaded and finished evaluating.
+
設置此 Boolean attribute 是為了指示瀏覽器, script 應在 document 解析後,但在 firing {{event("DOMContentLoaded")}} 之前被執行。
+
具有 defer 屬性的 scripts 將阻止觸發DOMContentLoaded 事件,直到 scripts load 完成並且 finished evaluating。

如果沒有 src 屬性的話,就不能用這個屬性(例如行內腳本):在這種情況下,它將失去作用。

+ +

The defer attribute has no effect on module scripts — they defer by default.

-
To achieve a similar effect for dynamically inserted scripts use async=false instead. Scripts with the defer attribute will execute in the order in which they appear in the document.
+
+

Scripts with the defer attribute will execute in the order in which they appear in the document.

+ +

This attribute allows the elimination of parser-blocking JavaScript where the browser would have to load and evaluate scripts before continuing to parse. async has a similar effect in this case.

+
{{htmlattrdef("integrity")}}
This attribute contains inline metadata that a user agent can use to verify that a fetched resource has been delivered free of unexpected manipulation. See Subresource Integrity.
{{htmlattrdef("nomodule")}}
@@ -124,7 +130,7 @@ translation_of: Web/HTML/Element/script

以下示例展示如何在 HTML4 與 HTML5 使用 <script> 屬性。

-
<!-- HTML4 與  (x)HTML -->
+
<!-- HTML4 與  (x)HTML -->
 <script type="text/javascript" src="javascript.js"></script>
 
 <!-- HTML5 -->
@@ -135,7 +141,7 @@ translation_of: Web/HTML/Element/script
 
 

有針對 type 屬性支援 module(模組)的瀏覽器,會忽略 nomodule 屬性的程式碼。這能讓那些不支援模組的瀏覽器,提供替代的使用方法。

-
<script type="module" src="main.mjs"></script>
+
<script type="module" src="main.mjs"></script>
 <script nomodule src="fallback.js"></script>

規範

@@ -157,12 +163,12 @@ translation_of: Web/HTML/Element/script {{SpecName('HTML5 W3C', 'scripting-1.html#script', '<script>')}} {{Spec2('HTML5 W3C')}} -   + {{SpecName('HTML4.01', 'interact/scripts.html#h-18.2.1', '<script>')}} {{Spec2('HTML4.01')}} -   + {{SpecName('Subresource Integrity', '#htmlscriptelement', '<script>')}} -- cgit v1.2.3-54-g00ecf