---
title: "Jquery实现定时执行操作setInterval和clearInterval、setTimeout函数"
author: "hae"
date: "2014-08-06T18:50:00Z"
tags: []
categories: ["Web前端"]
slug: "jquery-setinterval-clearinterval-settimeout"
draft: false
lastmod: "2014-08-06T18:50:43Z"
id: 2101078
url: "https://hae.iteye.com/blog/2101078"
---

1.setInterval()用法：

```
var idInt = setInterval(function(){},2000);
```

 2.clearInterval用法：

```
clearInterval(idInt);
```

 

另，通过setTImeOut()也可以设置定时操作，具体demo如下：

```
function viewInExplorerStatus() {  
  var date = new Date();  
  s = date.getYear() + "年" +   
      (date.getMonth()+1) + "月" +   
      date.getDate() + "日" +   
      date.getHours() + "点" +   
      date.getMinutes() + "分" +   
      date.getSeconds() + "秒";  
  if (!Flag) {  
    s = "";  
  }  
  window.status = "欢迎您，User !  当前在线人数：8.当前时间：" + s;
  setTimeout("viewInExplorerStatus();", 1000);  
}
```