ExtJS Button的事件和方法定義


ExtJS Button的事件和方法定義: 

Js代碼    收藏代碼
  1. Ext.onReady(function(){  
  2.                 //構造函數的參數傳入一個字面量- renderTo, text  
  3.                 //minWidth最小寬度,無論字有多大都是100像素寬度  
  4.                 //handler:指定一個函數句柄,在默認事件觸發時的函數調用  
  5.                 //此時的默認事件為click  
  6.                 //這是事件定義的第一種方法  
  7.                 var _button = new Ext.Button({  
  8.                     //Ext.getBody().dom == document.body;  
  9.                     renderTo: Ext.getBody(),  
  10.                     text: "確定",  
  11.                     minWidth: 100,  
  12.                     handler: function(){  
  13.                         alert("歡迎學習ExtJS");  
  14.                     }  
  15.                 });  
  16.                 //text是Ext.Button的只讀屬性  
  17.                 alert(_button.text);  
  18.                 //setText是Ext.Button的設置Text方法  
  19.                 _button.setText("取消");  
  20.                  
  21.                 //listeners是在對象在被初始化前,就將一系列事件定義的手段  
  22.                 //這是事件定義的第二種方法(推薦程度5顆星)  
  23.                 var button2 = new Ext.Button({  
  24.                         renderTo: Ext.getBody(),  
  25.                         text: "Listeners Test",  
  26.                         minWidth:100,  
  27.                         listeners:{  
  28.                                "click":function(){  
  29.                                       alert("Listeners Test");  
  30.                                }  
  31.                         }  
  32.                 });  
  33.                                                  
  34.                //這是事件定義的第三種方法  
  35.                var _button3 = new Ext.Button({  
  36.            renderTo: Ext.getBody(),  
  37.            text: "On方法的事件定義",  
  38.                         minWidth:100  
  39.                 });  
  40.                _button3.on("click"function(){  
  41.                         alert("on的事件方法");  
  42.                });  
  43.             });  




extjs  button  用法: 

Js代碼    收藏代碼
  1. Ext.QuickTips.init();  
  2.         var buttonName = new Ext.Button({  
  3.   id:"buttonName",  
  4.                text:"Button組件基本用法",  
  5.                tooltip:"提示信息:Button組件基本用法",  
  6.    //提示信息,如果需要顯示提示信息,需要使用Ext.QuickTips.init();  
  7.                
  8.               tooltipType:"title"//定義顯示提示信息的類型,有qtip和title兩種方式,默認是qtip  
  9.                
  10.               type:"button"//按鈕類型:可以是submit, reset or button  默認是 button  
  11.                
  12.               autoShow:true,  //默認false,自動顯示  
  13.               
  14.                hidden:false,  //默認false,是否隱藏  
  15.               
  16.                hideMode:"offsets"//隱藏方式,默認display,可以取值:display,offsets,visibility  
  17.                
  18.               cls:"cssButton"//樣式定義,默認""  
  19.               
  20.                disabled:false//是否可用,默認false  
  21.               
  22.                disabledClass:"",  //默認x-item-disabled  
  23.               
  24.                enableToggle:true//默認false  
  25.               
  26.                pressed:false//設置按鈕是否已經被按下,默認是false  
  27.               
  28.                html:"Ext",//默認""  
  29.               
  30.                handleMouseEvents:true//默認true,如果為false,那么mouseout mouseover就不能被觸發  
  31.                
  32.               //x:number,y:number,在容器中的x,y坐標    
  33.                
  34.                handler:function(){Ext.Msg.alert('提示消息框','測試Button組件:handler事件!');},//添加事件  
  35.               
  36.                listeners:{//添加監聽事件 可以結合handler測試這兩個事件哪個最先執行  
  37.                   "click":function(){  
  38.                        Ext.Msg.alert('提示消息框','測試Button組件:listeners事件!');  
  39.                        Ext.getCmp("buttonName").hide();//隱藏按鈕  
  40.                   }  
  41.               },  
  42.               
  43.                cls:"x-btn-text-icon",//添加圖標前需要設置該屬性  
  44.                
  45.               icon:"house.gif"//圖標的地址  
  46.               
  47.                //plugins : Object/Array 擴展插件時使用  
  48.               
  49.                repeat:false,  //默認false ,如果為true,需要設置mouseover事件  
  50.               
  51.                renderTo:"Bind_Button" //將組件的顯示效果渲染到某個節點的ID  
  52.                
  53.         });  


配置: 
1. id:"buttonName", 
2. text:"Button組件基本用法", 
3. tooltip:"提示信息:Button組件基本用法", //提示信息,如果需要顯示提示信息,需要使用Ext.QuickTips.init(); 
4. ooltipType:"title", //定義顯示提示信息的類型,有qtip和title兩種方式,默認是qtip 
5. ype:"button", //按鈕類型:可以是submit, reset or button  默認是 button 
6. autoShow:true,  //默認false,自動顯示 
7. hidden:false,  //默認false,是否隱藏 
8. hideMode:"offsets", //隱藏方式,默認display,可以取值:display,offsets,visibility 
9. cls:"cssButton", //樣式定義,默認"" 
10. disabled:false, //是否可用,默認false 
11. disabledClass:"",  //默認x-item-disabled 
12. enableToggle:true, //默認false 
13. pressed:false, //設置按鈕是否已經被按下,默認是false 
14. html:"Ext",//默認"" 
15. handleMouseEvents:true, //默認true,如果為false,那么mouseout mouseover就不能被觸發 
16. x:number,y:number,在容器中的x,y坐標  
17. handler:function(){Ext.Msg.alert('提示消息框','測試Button組件:handler事件!');},//添加事件 
18. listeners:{//添加監聽事件 可以結合handler測試這兩個事件哪個最先執行 
         "click":function(){ 
             Ext.Msg.alert('提示消息框','測試Button組件:listeners事件!'); 
             Ext.getCmp("buttonName").hide();//隱藏按鈕 
           } 
   }, 
19. cls:"x-btn-text-icon",//添加圖標前需要設置該屬性 
20. icon:"house.gif", //圖標的地址 
21. plugins : Object/Array 擴展插件時使用 
22. repeat:false,  //默認false ,如果為true,需要設置mouseover事件 
23. renderTo:"Bind_Button" //將組件的顯示效果渲染到某個節點的ID 
常用方法: 
1. enable();激活按鈕 
2. disable();禁用按鈕 
3. destroy();消滅按鈕 
4. focus();按鈕獲取焦點 
5. getText();獲取按鈕上的文本 
6. hide();隱藏按鈕 
7. show();顯示按鈕 
8. setText( String text );設置按鈕上的文本 
9. setVisible( Boolean visible );設置按鈕是否隱藏 
10. buttonName.purgeListeners(); 
//使用該方法,意思是清除所有的監聽事件,所以當執行該句后就不會再執行listeners的click事件了。按鈕就不會被隱藏了。 
11. buttonName.setHandler(fn);       
        //也可以通過這種方式設置handler事件: 
        buttonName.setHandler(function(){Ext.Msg.alert('提示消息框','測試Button組件:setHandler事件!');}); 
12. buttonName.on(eventName,fn); 
       //下面的事件可以自己測試下 
        buttonName.on("click",function(){ 
            Ext.Msg.alert('提示消息框','測試Button組件:click事件!'); 
        }); 
         buttonName.on("mouseover",function(){ 
            Ext.Msg.alert('提示消息框','測試Button組件:mouseover事件!'); 
        }); 
        buttonName.on("mouseout",function(){ 
            Ext.Msg.alert('提示消息框','測試Button組件:mouseout事件!'); 
        }); 
             
mouseout : ( Button this, Event e ) ; 
mouseover : ( Button this, Event e ); 
beforedestroy : ( Ext.Component this ) ; 
beforehide : ( Ext.Component this ) ; 
beforerender : ( Ext.Component this ) 
beforeshow : ( Ext.Component this ) 
click : ( Button this, EventObject e ) 
destroy : ( Ext.Component this ) 
disable : ( Ext.Component this ) 
enable : ( Ext.Component this ) 
hide : ( Ext.Component this ) 
show : ( Ext.Component this ) 
render : ( Ext.Component this ) 
<!--EndFragment-->


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM