這個問題在這里已經有了答案: 將變數直接從 <script> HTML 標簽傳遞給 Javascript 3 個回答 1 小時前關閉。
如何從 html 檔案定義一個值并將其傳遞給腳本標簽?
例如在下面我想傳遞“myparameter”的值的地方做類似的事情
<script src="app.js" myparameter="myvalue" type="module"></script>
uj5u.com熱心網友回復:
如果你有這樣的 html:
<script src="app.js" myparameter="myvalue" type="module"></script>
在js腳本中:
document.currentScript.getAttribute('myparameter'); //myvalue
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/355157.html
標籤:javascript
下一篇:回傳函式不會在React中呈現
