gpt4 book ai didi

javascript - 如果不存在则加载 Angular

转载 作者:行者123 更新时间:2023-12-02 17:14:19 25 4
gpt4 key购买 nike

如果 angularjs 文件不存在,是否可以加载?我正在制作一个基于 Angular 的小部件,并希望客户能够使用该小部件。如果主机页面上不存在 Angular,则加载脚本。

我是 Angular 的新手,我真的很想学习(掌握)这个令人惊叹的框架。

我发现了我想要的 jQuery 变体。如果有人有一个(更好的) Angular 版本的片段或网站,他可以推荐给我,这会对我有很大帮助

这是代码:

    <script type="text/javascript">
(function() {

// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function () { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else { // Other browsers
script_tag.onload = scriptLoadHandler;
}
// Try to find the head, otherwise default to the documentElement
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
// The jQuery version on the window is the one we want to use
jQuery = window.jQuery;
main();
}
/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
// Restore $ and window.jQuery to their previous values and store the
// new jQuery in our local jQuery variable
jQuery = window.jQuery.noConflict(true);
// Call our main function
main();
}
/******** Our main function ********/
function main() {
jQuery(document).ready(function($) {
// We can use jQuery 1.4.2 here
});
}

})(); // We call our anonymous function immediately
</script>

提前谢谢

最佳答案

if(typeof angular == 'undefined') {
//angular is not loaded correctly, deal with it here
}

关于javascript - 如果不存在则加载 Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24573050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com