HTMLScriptElement: src 屬性
Baseline 廣泛可用 *
HTMLScriptElement 介面的 src 屬性是一個字串,表示外部指令碼的 URL;這可以作為在文件中直接嵌入指令碼的替代方法。
它反映了 <script> 元素的 src 屬性。
值
字串。
示例
假設程式碼執行在一個 URL 為 https://example.com 的網站上。
html
<script id="script-with-src" type="module" src="/main.js"></script>
<script id="script-without-src" type="module"></script>
js
const script_with_src = document.getElementById("script-with-src");
console.log(script_with_src.src); // Output: "https://example.com/main.js"
const script_without_src = document.getElementById("script-without-src");
console.log(script_without_src.src); // Output: ""
規範
| 規範 |
|---|
| HTML # dom-script-src |
瀏覽器相容性
載入中…