[英]How load and execute (scoped) script by $.getScript()
我需要動態加載這樣包裝的腳本:
{
(function () {
"use strict";
function myFunction() {
// code
}
myFunction();
})();
}
我使用 jquery function $.getScript()
腳本已加載,但未執行。 (在網站管理員工具中,我可以看到請求和響應 - 腳本在這里有內容)
我如何加載和自動執行這樣的腳本?
I was solve this problem with another ajax request not to javascript file but to html file (html response) with basic tag script
with url address. 還向其中傳遞了一些變量。
所以我的 html 看起來像這樣:
<script type="text/javascript">
var varPassedToScript = 1;
</script>
<script type="text/javascript" src="https://www.urlToScript.com/script.js"></script>
它有效...
如果有人有更好的解決方案 - 我很好奇
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.