我知道如何在HTML文件中包含CDN。
<!DOCTYPE html>
<html>
<head>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
</body>
</html>
但我想做的是:
我想在我的javascript文件中包含像jquery这样的CDN。
可能是我想做的事情是不可能的
实际上,我想从我的javascript文件中调用 BootstrapDialog.Confirm 。
所以,我想在js文件中包含BootstrapDialog所需的CDN
然后我可以调用 BootstrapDialog.Confirm 。
如果我的问题不合理,请原谅我,因为我是初学者。
答案 0 :(得分:7)
您可以在Javascript中执行此操作:
var jQueryScript = document.createElement('script');
jQueryScript.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js');
document.head.appendChild(jQueryScript);
答案 1 :(得分:0)
使用document.write可以包含cdn
document.write(
unescape("%3Cscript src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E")
);