jquery 定时器的使用
来源:互联网 发布:照片调色软件 编辑:程序博客网 时间:2024/06/05 18:21
在页面上定时做某些事,如:站内短信提醒:当发信人给收件人发送一条短信,收件人在浏览此网站的时候,网站右下角会弹出一个框,提醒收件人已经收到一条短信,收件人可通过点击提醒,查看他的短信。
以下我写了一个例子,综合了几个具体功能在一起:
1、jquery修改页面上某个div中的内容
2、时间格式化功能
3、定时器设置,开始和停止
代码如下:
01
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
02
<
head
>
03
04
<
title
>jquery定时器使用方法</
title
>
05
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=utf-8"
/>
06
<
style
type
=
"text/css"
>
07
#div1{ font-size:36px; color:#f00; font-weight:bold; }
08
</
style
>
09
</
head
>
10
11
<
body
>
12
<
div
id
=
"div1"
></
div
>
13
<
script
type
=
"text/javascript"
src
=
"http://www.aspbc.com/js/jquery.js"
></
script
>
14
<
input
type
=
"button"
name
=
"startChat"
id
=
"startChat"
value
=
"开始"
>
15
<
input
type
=
"button"
name
=
"closeChat"
id
=
"closeChat"
value
=
"停止"
>
16
<
script
type
=
"text/javascript"
>
17
$(function(){
18
chat();
19
run(); //加载页面时启动定时器
20
var interval; //定义一个定时器
21
function run() {
22
interval = setInterval(chat, "1000"); //定时的设置
23
}
24
function chat() {
25
var d=new Date().format('yyyy-MM-dd hh:mm:ss');
26
$("#div1").html(d); //jquery修改页面上div中的内容
27
}
28
$("#closeChat").click(function(){
29
clearTimeout(interval); //关闭定时器
30
})
31
$("#startChat").click(function(){
32
chat();
33
interval = setInterval(chat, "1000"); //启动定时器
34
})
35
});
36
37
Date.prototype.format = function(format)
38
{
39
var o = {
40
"M+" : this.getMonth()+1, //month
41
"d+" : this.getDate(), //day
42
"h+" : this.getHours(), //hour
43
"m+" : this.getMinutes(), //minute
44
"s+" : this.getSeconds(), //second
45
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
46
"S" : this.getMilliseconds() //millisecond
47
}
48
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
49
(this.getFullYear()+"").substr(4 - RegExp.$1.length));
50
for(var k in o)if(new RegExp("("+ k +")").test(format))
51
format = format.replace(RegExp.$1,
52
RegExp.$1.length==1 ? o[k] :
53
("00"+ o[k]).substr((""+ o[k]).length));
54
return format;
55
}
56
</
script
>
57
</
body
>
58
</
html
>
- jquery 定时器的使用
- 构建一个简单的jquery定时器,方便随时拿来使用。
- jquery定时器的简单代码
- Jquery中使用定时器setInterval和setTimeout
- 定时器的使用
- C#定时器的使用
- C#定时器的使用
- java定时器的使用
- 内核定时器的使用
- 定时器的使用
- linux定时器的使用
- linux定时器的使用
- linux定时器的使用
- linux定时器的使用
- 定时器的使用
- C#定时器的使用
- 内核定时器的使用
- 使用glib的定时器
- Servlet处理HTTP响应
- 创建Flex项目(无服务器的情况下)
- 面试题20:顺时针打印矩阵 ***
- Cocos2D-HTML5 MoonWarriors Android Dev (wwashington) -- Android 编译指南
- hdu 1026 (优先队列+bfs)
- jquery 定时器的使用
- Qt国际化
- 07-九藏天下面试总结
- username +password
- iSCSI
- Java 7从入门到精通 目录结构
- XCode4.0之HelloWorld创建及说明----------同样适合XCode4.6.2
- 使用Maven管理依赖JAR文件,自定义项目布局,利用ANT生成不同的发布包
- Oracle Profile 使用详解