Extjs4学习笔记-Ext.util.TaskRunner

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Ext.util.TaskRunner</title>
		
		<link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css" />
		<script type="text/javascript" src="../extjs/bootstrap.js"></script>
		<script type="text/javascript" src="../extjs/ext-lang-zh_CN.js"></script>
		
		<style type="text/css">
			#div1 {
				width: 160px;
				height: 160px;
				line-height: 80px;
				padding: 0;
				font-size: 80px;
				text-align: center;
				font-weight: bold;
				display: none;
			}
		</style>
		
		<script type="text/javascript">
			
			Ext.onReady(function() {
				
				var input = Ext.getDom("input1");
				var div = Ext.getDom("div1");
				var button = Ext.getDom("stopButton");
				
				var task = {
					run: function(count) {
						var v = parseInt(input.value);
						var d = v - count;
						if(v > count) {
							div.innerHTML = v - count;
						} else {
							input.removeAttribute("readonly");
							div.style.display = "none";
							button.value = "开始";
							Ext.MessageBox.alert("信息", "时间到!");
						}
					},
					interval: 1000,
					duration: 1000
				}
				
				//为文本框绑定keypress事件,禁止输入非数字字符
				Ext.EventManager.on("input1", "keypress", function(e, el) {
					var key = e.getKey();
					if(key < e.ZERO || key > e.NINE) {
						e.stopEvent();
					}
				});
				
				
				//为按钮绑定单击事件
				Ext.EventManager.on("stopButton", "click", function(e, el) {
					var t = task;
					if(el.value == "停止") {
						el.value = "开始";
						input.removeAttribute("readonly");
						div.style.display = "none";
						Ext.TaskManager.stop(task);
					} else {
						var v = parseInt(input.value);
						if(v > 0) {
							t.duration = v * 1000;
							input.readOnly = "true";
							div.innerHTML = v;
							div.style.display = "block";
							el.value = "停止";
							Ext.TaskManager.start(task);
						}
					}
				});
				
				//封装好的单击事件:Ext.util.ClickRepeater
				// Ext.create("Ext.util.ClickRepeater", "stopButton", {
					// pressedCls: 'pressed',
					// listeners: {
						// click: function(e) {
							// var el = button;
							// var t = task;
							// if(el.value == "停止") {
								// el.value = "开始";
								// input.removeAttribute("readonly");
								// div.style.display = "none";
								// Ext.TaskManager.stop(task);
							// } else {
								// var v = parseInt(input.value);
								// if(v > 0) {
									// t.duration = v * 1000;
									// input.readOnly = "true";
									// div.innerHTML = v;
									// div.style.display = "block";
									// el.value = "停止";
									// Ext.TaskManager.start(task);
								// }
							// }
						// }
					// }
				// });
				
			});
			
		</script>
		
	</head>
	<body>
		<div style="padding: 20px 0 0 20px;">
			<input id="input1" type="text" value="10" />
			<input id="stopButton" type="button" value="开始" />
			<div id="div1"></div>
		</div>
	</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值