setTimeout不适用于jQuery [英] setTimeout not working with jquery

查看:85
本文介绍了setTimeout不适用于jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很好的jquery扩展函数,但是当我通过setTimout传递它时,它不会等待指定的时间并立即运行.

I have a jquery extended function that works perfectly but when i pass it through the setTimout it does not wait the the specified period and runs straight away.

jQuery(document).ready(function($) {    
  setTimeout($.mainmenuslider({
    trigger:'close'
  }),6000);  
});

任何想法?

推荐答案

您需要传递匿名方法来执行所需的操作,例如:

You need to pass an anonymous method to do what you want, like this:

jQuery(function($) {    
    setTimeout(function() {
      $.mainmenuslider({
        trigger:'close'
      });
    }, 6000);    
});

否则,您将尝试传递函数的 result (使其立即执行,以后不再运行).

Otherwise you're trying to pass the result of the function (making it execute immediately, and run nothing later).

这篇关于setTimeout不适用于jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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