且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何查找链接的异步脚本是否已加载?

更新时间:2022-05-19 19:32:55

您还可以使用 $.ajaxSuccess :

You can also use $.ajaxSuccess:

$(document).ajaxComplete(function(ev, jqXhr, options) {
  // You could be as specific as you need to here.
  if ( options.url.match('second.js') ) {
    doSecond();
  }
});

或者,您可以在ajaxComplete内执行此操作:

Alternatively, you could do this inside ajaxComplete:

$(document).ajaxComplete(function(ev, jqXhr, options) {
  // You could simplify to 
  // doSecond && doSecond()
  // if you can trust that it will always be a function
  if ( doSecond && $.isFunction(doSecond) ) {
    doSecond();
  }
});