我知道,感谢本教程<script src="/widget/widget.js?type=normal" type="text/javascript"></script>
,如果主机网站没有它,如何动态加载 jQuery(例如调用):
(function () {
var jQuery;
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", pathWidget + "/scripts/jquery-1.7.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function () { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else {
script_tag.onload = scriptLoadHandler;
}
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
jQuery = window.jQuery;
main();
}
function scriptLoadHandler() {
jQuery = window.jQuery.noConflict(true);
main();
}
function main() {
jQuery(document).ready(function ($) {
});
}
})();
好吧,现在我想为 jquery 库做同样的事情。让我们说 jQuery Cycle。
我试过了:
var script_cycle = document.createElement('script');
script_cycle.setAttribute("type", "text/javascript");
script_cycle.setAttribute("src", pathWidget + "/scripts/jquery.cycle.all.js");
后 :
script_tag.setAttribute("src", pathWidget + "/scripts/jquery-1.7.min.js");
但是当我将循环加载到准备好的文档中时,我收到了这个错误:
$("#myRotator").cycle is not a function
我哪里错了?