Java蜘蛛人 欢迎大家

欢迎大家 来到我的blog , 如果我身边的朋友 有什么不懂可以直接来问我 我会细心的帮助你的. 如果网络上的朋友有什么不懂的 可以加我Java蜘蛛人 QQ48187537
posts - 54, comments - 192, trackbacks - 0, articles - 1

Ext js 事件切换

Posted on 2009-03-14 15:33 Java蜘蛛人 --郑成桥 阅读(750) 评论(0)  编辑  收藏
test.js
Ext.onReady(function(){
    
    Person 
= function(name)
    {
        
this.name= name;
        
this.addEvents("walk","eat","sleep");
    }
    
    
    
    Person2 
= function(name)
    {
        
this.name= name;
        
this.addEvents("aa","bb","cc");
    }
    
    
    
        
    Ext.extend(Person2,Ext.util.Observable,{
        info:
function(event)
        {
            
return this.name+"is"+event+"ing.";
        }
    });
    
    
    
    Ext.extend(Person,Ext.util.Observable,{
        info:
function(event)
        {
            
return this.name+"is"+event+"ing.";
        }
    });
    
    
    
    
        
var person2 = new Person2("郑成桥");
    
        person2.on('aa',
function (){
            Ext.Msg.alert(
"event",this.name+"哈哈");            
        });
        
        person2.on(
"bb",function(frunt,shuiguo){
            Ext.Msg.alert(
"event",this.name+"面包:"+frunt+"葡萄"+shuiguo);
        });
        person2.on(
"cc",function(time){
            Ext.Msg.alert(
"event",this.name+"老子要从"+time.format("h")+"呵呵");
        });
    
    
    
    
    
var person = new Person("zcq");
    
        person.on('walk',
function (){
            Ext.Msg.alert(
"event",this.name+"走撒");            
        });
        
        person.on(
"eat",function(frunt,shuiguo){
            Ext.Msg.alert(
"event",this.name+"要吃:"+frunt+""+shuiguo);
        });
        person.on(
"sleep",function(time){
            Ext.Msg.alert(
"event",this.name+"要从"+time.format("h")+"开始睡觉");
        });
        
    
        
        
        
        Ext.get(
"walk").on("click",function(){
    
        person2.fireEvent(
"aa");
    });
    
    Ext.get(
"eat").on("click",function(){
        person2.fireEvent(
"bb","苹果","woman");
    });
    
    Ext.get(
"sleep").on("click",function(){
        person2.fireEvent(
"cc",new Date());
    });
        
        
        
        
    Ext.get(
"walk").on("click",function(){
    
        person.fireEvent(
"walk");
    });
    
    Ext.get(
"eat").on("click",function(){
        person.fireEvent(
"eat","苹果","女人");
    });
    
    Ext.get(
"sleep").on("click",function(){
        person.fireEvent(
"sleep",new Date());
    });
    
    
     
    
    Ext.get(
"capture1").on("click",function(){
          Ext.util.Observable.releaseCapture(person);
    });
    
    Ext.get(
"capture2").on("click",function(){
        Ext.util.Observable.capture(person,
function(){
            
return false;
        });
    });
      
});

index1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  
<head>
    
    
<title>My JSP 'index.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
    
<meta http-equiv="cache-control" content="no-cache">
    
<meta http-equiv="expires" content="0">    
    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    
<meta http-equiv="description" content="This is my page">
    
<!--
    
<link rel="stylesheet" type="text/css" href="styles.css">
    
-->
    
     
<script type="text/javascript" src="js/adapter/ext/ext-base.js"></script>  
    
<script type="text/javascript" src="js/ext-all.js"></script>  
     
<link rel="stylesheet" type="text/css" href="js/resources/css/ext-all.css" />  
      
<script type="text/javascript" src="js/js.js" ></script>
      
<script type="text/javascript" src="js/test1.js" ></script>
        
<link rel="stylesheet" type="text/css" href="js/examples.css" />
        
<script type="text/javascript" src="js/examples.js" ></script>
  
</head>
     
<style type="text/css">
        .x
-window-dlg .ext-mb-download {
            background:transparent url(images
/download.gif) no-repeat top left;
            height:46px;
        }
    
</style>
  
  
<body>
    
<input type="button" id="walk"  value="walk" />
    
<input type="button" id="eat"  value="eat" />
    
<input type="button" id="sleep"  value="sleep" />
    
<br>
     
<button id="capture1">事件切换1</button>
     
<button id="capture2">事件切换2</button>
  
</body>
</html>



只有注册用户登录后才能发表评论。


网站导航: