jQuery 执行订单

发布于 2024-09-19 10:56:27 字数 605 浏览 4 评论 0原文

我正在使用以下 jQuery 插件,它在指定元素上有单击操作时执行:

http ://www.andresvidal.com/labs/relcopy.html

我还为同一元素创建了一个点击函数,但我希望它在插件之后执行。但事实并非如此,点击函数总是首先执行,从而导致问题。

例如,请检查我下面的代码,我是 jQuery 新手,因此任何建议/帮助将不胜感激!

$.getScript('../js/relCopy.js', function() {

            $('#AddTable').relCopy({
                limit: 10,
                excludeSelector: '.newListSelected'
            });

$('#AddTable').click(function() {
    do something here after relcopy has finished
});

I'm using the following jQuery plugin and it executes when there's a click action on the specified element :

http://www.andresvidal.com/labs/relcopy.html

I also created a click function for the same element, but I expected it to execute after the plugin. However that isn't the case, the click function always executes first, thus causing problems.

Please check my code below for example, I'm new to jQuery so any suggestions / help would really be appreciated!

$.getScript('../js/relCopy.js', function() {

            $('#AddTable').relCopy({
                limit: 10,
                excludeSelector: '.newListSelected'
            });

$('#AddTable').click(function() {
    do something here after relcopy has finished
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

書生途 2024-09-26 10:56:27

事件处理程序按照它们绑定的顺序执行,并且由于 $.getScript( ) 在该脚本加载后执行,它在您的之后绑定它的点击处理程序。

因此,获取您想要的顺序,您需要按照您想要的顺序绑定,这意味着也在回调中绑定您的点击处理程序,如下所示:

$.getScript('../js/relCopy.js', function() {
  $('#AddTable').relCopy({
    limit: 10,
    excludeSelector: '.newListSelected'
  }).click(function() {
    //do something here after relcopy has finished
  });
});

Event handlers are executed in the order they were bound, and since the callback from $.getScript() executes after that script is loaded, it's binding it's click handler after yours.

So get the order you want you need to bind in the order you want, that means binding your click handler in the callback as well, like this:

$.getScript('../js/relCopy.js', function() {
  $('#AddTable').relCopy({
    limit: 10,
    excludeSelector: '.newListSelected'
  }).click(function() {
    //do something here after relcopy has finished
  });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文