延迟运行功能3秒钟? [英] Delay running a function for 3 seconds?

查看:105
本文介绍了延迟运行功能3秒钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将此功能延迟运行3秒钟:

I'm looking to delay running this function for 3 seconds:

<script type="text/javascript">
$('#FormsPageID table tr:nth-child(12) td:nth-child(2) div span span input')
  .on('focus', function(){
      var $this = $(this);
      if($this.val() == '4/11/2013'){
          $this.val('');
      }
  })
  .on('blur', function(){
      var $this = $(this);
      if($this.val() == ''){
          $this.val('4/11/2013');
      }
  });
</script>

我遇到的所有示例都涉及使用setTimeout在X秒后显示元素.但是我不确定这将如何应用于我的功能.

The examples I've come across all involve using setTimeout to or show an element after X seconds. But I'm unsure how that would apply to my function.

推荐答案

使用setTimeout:

Use setTimeout :

setTimeout(function(){$('#FormsPageID table tr:nth-child(12) td:nth-child(2) div span span input')
 .on('focus', function(){
      var $this = $(this);
      if($this.val() == '4/11/2013'){
          $this.val('');
      }
  })
  .on('blur', function(){
      var $this = $(this);
      if($this.val() == ''){
          $this.val('4/11/2013');
      }
  });}, 3000);

这篇关于延迟运行功能3秒钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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