<!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>