第二个$(文件).ready事件jQuery [英] second $(document).ready event jQuery

查看:115
本文介绍了第二个$(文件).ready事件jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些带有$(document).ready()的外部jQuery在文档就绪事件被触发后插入广告,如:

I'm using some external jQuery with $(document).ready() to insert adverts after the document ready event has fired, something like:

$(document).ready( function() {
  $('#leaderboard').html("<strong>ad code</strong>");     
});

这是为了防止广告加载缓慢阻止用户界面。到目前为止,它一直运作良好。

This is to prevent the UI being blocked by the slow loading of the adverts. So far it's been working well.

现在我需要通过我们的CMS系统插入更多广告,这不能成为外部JS文件的一部分,所以我'我想知道我可以使用第二个文档就绪事件并使用内联脚本标记插入它吗?如果是这样,首先执行外部JS文档就绪事件或内联脚本的执行顺序是什么?

Now I need to insert some more ads though our CMS system, this can't be part of the external JS file, so I'm wondering can I use a second document ready event and insert it using an inline script tag? If so, what will be the order of execution the external JS document ready event first or the inline script?

推荐答案

你可以使用尽可能多的事件方法,jquery将它们连接在一个队列中。方法调用的顺序与定义顺序相同 - 最后添加的是最后调用的。

You can use as many event methods as you want, jquery joins them in a queue. Order of method call is same as definition order - last added is last called.

一个有用的东西也可能是,你可以使用ajax加载带有脚本的html代码代码加载到DOM $()。ready()也将被调用,因此您可以动态加载广告。

A useful thing may be also that, you can load html code with script using ajax and when code is loaded into DOM $().ready() also will be called, so you can load ads dynamically.

这篇关于第二个$(文件).ready事件jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆