ExtJS 4.2 中自定义事件

前台HTML:

ExtJS 4.2 中自定义事件
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="js/extjs/resources/css/ext-all-neptune-debug.css">
<script type="text/javascript" src="js/extjs/ext-all-debug.js"></script>
<script type="text/javascript" src="js/extjs/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/all.js"></script>
<title>ExtJS</title>
</head>
<body>
<body>
<button id="walk">walk</button>
<button id="eat">eat</button>
<button id="sleep">sleep</button>
</body>
</body>
</html>
ExtJS 4.2 中自定义事件

JS代码:

ExtJS 4.2 中自定义事件
 Person = function(name) {
// ExtJS 4 中一定要这句构造函数
Person.superclass.constructor.call(this, name);
this.name = name;
this.addEvents("walk", "eat", "sleep");
}; Ext.extend(Person, Ext.util.Observable, {
info : function(event) {
return this.name + ' is ' + event + 'ing.';
}
}); Ext.onReady(function() {
Ext.get('walk').on('click', function() {
person.fireEvent('walk');
}); Ext.get('eat').on('click', function() {
person.fireEvent('eat', '早餐', '中餐', '晚餐');
}); Ext.get('sleep').on('click', function() {
// 此处不能用time = new Date(),然后time.format("H")了
person.fireEvent('sleep', Ext.Date.format(new Date(), 'H'));
}); var person = new Person('Lingo');
person.on('walk', function() {
Ext.Msg.alert('event', person.name + "在走啊走啊。");
});
person.on('eat', function(breakfast, lunch, supper) {
Ext.Msg.alert('event', person.name + "要吃" + breakfast + "," + lunch + "和" + supper + "。");
});
person.on('sleep', function(time) {
Ext.Msg.alert('event', person.name + "从" + time + "点开始睡觉啦。");
});
});
ExtJS 4.2 中自定义事件
上一篇:lintcode :Ugly Numbers 丑数


下一篇:GO语言学习笔记之Linux环境下安装GO语言