关闭

extjs事件demo

258人阅读 评论(0) 收藏 举报

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../lib/ext-all.css" />
	<script type="text/javascript" src="../lib/ext-base.js"></script>
    <script type="text/javascript" src="../lib/ext-all.js"></script>
	<script type="text/javascript" src="helloword.js"></script>
</head>
<script type="text/javascript">
Ext.namespace("hb.com");

hb.com.Person=function(){
	this.addEvents("namechange","sexchange");
};

Ext.extend(hb.com.Person,Ext.util.Observable,{
	name:"",
	sex:"",
	setName:function(_name){
		if(this.name!=_name){
			this.fireEvent("namechange",this,this.name,_name);
			this.name=_name
		}
	},
	setSex:function(_sex){
		if(this.sex!=_sex){
			this.fireEvent("sexchange",this,this.sex,_sex);
			this.sex=_sex;
		}
	}
});

var _person = null;

button_click=function(){
	_person.setName(prompt("输入姓名",""));
	_person.setSex(prompt("输入性别",""));
};

Ext.onReady(function(){
	var txt_name = Ext.get("txt_name");
	var txt_sex = Ext.get("txt_sex");
	_person = new hb.com.Person();
	_person.on("namechange",function(_person,_old,_new){
		txt_name.dom.value = _new;
	});
	_person.on("sexchange",function(_person,_old,_new){
		txt_sex.dom.value = _new;
	});
	_person.on("namechange",function(_person,_old,_new){
		document.title = _new;
	});
	
});

</script>
<body>
    <h1></h1>
    姓名<input type="text" id="txt_name"><br>
	性别<input type="text" id="txt_sex"><br>
	<input type="button" value="输入" onclick="button_click()"><br>
</body>
</html>
 

 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:330086次
    • 积分:8946
    • 等级:
    • 排名:第2254名
    • 原创:1096篇
    • 转载:14篇
    • 译文:0篇
    • 评论:5条
    最新评论