Javascript 无法动态加载jQuery UI-未捕获类型错误:无法读取属性';用户界面';未定义的

Javascript 无法动态加载jQuery UI-未捕获类型错误:无法读取属性';用户界面';未定义的,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我动态加载jQuery和jQuery UI文件。jQuery文件加载成功,但当jQuery UI文件加载时发生错误 以下是控制台中显示的内容:Uncaught TypeError:无法读取未定义的属性“ui” 我的代码如下 (function() { var jQuery; if (window.jQuery === undefined) { var script_tag = document.createElement('script'); script_tag.setAttr

我动态加载jQuery和jQuery UI文件。jQuery文件加载成功,但当jQuery UI文件加载时发生错误

以下是控制台中显示的内容:Uncaught TypeError:无法读取未定义的属性“ui”

我的代码如下

(function()
{
var jQuery;
if (window.jQuery === undefined)
{
    var script_tag = document.createElement('script');
    script_tag.setAttribute("type", "text/javascript");
    script_tag.setAttribute("src",
            "//code.jquery.com/jquery-1.11.0.min.js");




    if (script_tag.readyState)
    {
        script_tag.onreadystatechange = function()
        {
            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.getScript('http://code.jquery.com/ui/1.11.1/jquery-ui.min.js', function() {
            jQuery.noConflict(true);
        });
};
})();
有人能帮我吗?

使用:

$(document).ready(function() {}); 

这两种说法实际上完全相同。所以第二个电话只是第一个的捷径

$符号同样只是jQuery的快捷方式。如果您已将jQuery加载到您的网站中,则可以同时使用这两种方法

 (function($){
 }(jQuery));
在这里,您正在调用匿名函数(参数为$),并传入jQuery对象。

使用:

$(document).ready(function() {}); 

这两种说法实际上完全相同。所以第二个电话只是第一个的捷径

$符号同样只是jQuery的快捷方式。如果您已将jQuery加载到您的网站中,则可以同时使用这两种方法

 (function($){
 }(jQuery));

在这里,您正在调用匿名函数(以$作为参数),并传入jQuery对象。

只需从noConflict调用中删除true;这将放弃对$的控制,但留下jQuery供jQuery UI使用:

/******** Called once jQuery has loaded ******/

    function scriptLoadHandler() {
        // Restore $ to its previous values and store the
        // new jQuery in our local jQuery variable
        jQuery = window.jQuery.noConflict(); // no argument!
        // Call our main function
        main();
    }

只需从noConflict调用中删除true;这将放弃对$的控制,但留下jQuery供jQuery UI使用:

/******** Called once jQuery has loaded ******/

    function scriptLoadHandler() {
        // Restore $ to its previous values and store the
        // new jQuery in our local jQuery variable
        jQuery = window.jQuery.noConflict(); // no argument!
        // Call our main function
        main();
    }

这是一个独立的JS文件。它可以添加到任何项目并包括在内。为了完成您刚才提到的任务,jQuery应该在前面包括在内。这里我们动态加载jQuery文件。我试过你说的,没用,这是一个独立的JS文件。它可以添加到任何项目并包括在内。为了完成您刚才提到的任务,jQuery应该在前面包括在内。这里我们动态加载jQuery文件。我确实试过你说的,它不起作用,检查你的括号。发布时,它看起来像
main()
jQuery(文档)。就绪…
在标记中没有正确关闭。请仔细检查括号。发布时,它看起来像
main()
jQuery(document).ready…
在标记中没有正确关闭。