我有兩個文件。HTML 文件:<!DOCTYPE html><html> <head> <script type="text/javascript">function update_layout(){ var new_source = document.createElement('script') new_source.src = 'script_code.js' new_source.type = 'text/javascript' document.getElementsByTagName('head')[0].appendChild(new_source)}function do_layout(){ alert(Lay_Table['nam'])} </script> </head> <body> <input type="button" value="Update" onclick="update_layout();do_layout();"/> </body></html>和一個名為“script_code.js”的 JavaScript 文件:Lay_Table = {}Lay_Table['nam'] = 'US 104 Key'當我單擊“更新”按鈕時,我收到錯誤,而不是包含文本“US 104 Key”的警報。我在 Stack Overflow 上查看過非常類似的問題,但無法找出問題所在。我是否犯了一個錯誤,或者由于安全原因不再允許使用此方法?我正在使用谷歌瀏覽器。
動態更改腳本源不起作用
慕萊塢森
2023-08-05 19:40:58