JQuery UI Loaded Event?

岁酱吖の 提交于 2019-12-06 07:24:00

问题


Is there anyway to not only detect that the jquery UI loaded but also fire an event when it does? Right now I have code wrapped in a $(document).ready() function but sometimes the UI code errors out because the UI library did not fully load (everything is loading in the correct order). The code works 99% of the time but about 1% of the users get a javascript error related to the UI not loading.

Something like

$(document).ready(function() {
  jQuery.ui.ready(function() { ....

Is anything like this possible?

Thanks.


回答1:


You could try to load your plugin like jQuery-ui and other with getcript and hold the ready function(s) before the script is fully loaded

// Hold the ready function(s)
$.holdReady(true);

// Retrieve the script and unlock the ready function(s) when the script is loaded
$.getScript("myplugin.js", function() {
    $.holdReady(false);
});

Keeping you ready function(s) simple

$(document).ready(function() {

    // your code here

});



回答2:


I ran into a similar problem in the past. Use this:

if (typeof jQuery.ui != 'undefined') {
  //do something
}

Hope this helps!



来源:https://stackoverflow.com/questions/14328762/jquery-ui-loaded-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!