JQuery UI加载事件?

反正不仅检测到jquery UI已加载,而且还会触发事件吗? 现在我的代码包含在$(document).ready()函数中,但有时UI代码错误,因为UI库没有完全加载(一切都以正确的顺序加载)。 代码在99%的时间内工作,但大约1%的用户得到与未加载的UI相关的javascript错误。

就像是

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

这样的事情可能吗?

谢谢。

您可以尝试像jQuery-ui一样加载插件,使用getcript加载其他插件,并在脚本完全加载之前保留ready函数

 // 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); }); 

让您准备好function简单

 $(document).ready(function() { // your code here }); 

我过去遇到过类似的问题。 用这个:

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

希望这可以帮助!