Loading...
轻松掌握ExtJs系列教程二:使用Ext.Button组件
作者:GDNPC 日期:2009-05-24
本章介绍如何使用Ext.Button组件。如果大家使用IE的话建议安装IE Developer Toolbar,这样就能实时看到ext究竟生成了什么代码。不安装也可以,ext本身也自带了类似功能,下面例子就启用了debug功能。
效果如下图:

XML/HTML代码
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
- <script type="text/javascript" src="adapter/jquery/jquery.js"></script>
- <script type="text/javascript" src="adapter/jquery/ext-jquery-adapter.js"></script>
- <script type="text/javascript" src="ext-all-debug.js"></script>
- <script type="text/javascript">
- Ext.onReady(function(){
- Ext.QuickTips.init();
- var btn = new Ext.Button({
- text:"hello button!",
- allowDepress: true, //显示按钮按下效果,需要和enableToggle联合使用
- enableToggle: true, //为按钮添加开关效果
- disabled: false, //是否禁用
- hidden: false, //是否隐藏
- hideMode: "display", //隐藏模式,默认是display,也可以使用visibility或offsets(visibility和display的区别是前者隐藏但保留位置,后者隐藏而不保留位置,后续元素会自动补位)
- hideParent: false, //是否隐藏parent组件,例如一个button在一个div上,如果在隐藏button同时需要隐藏div,这个属性应该设为true
- disabledClass: '', //按钮禁用时所使用的样式,默认是:x-item-disabled
- id:"a", //就是id了,不给的话ext会自动赋值
- menu:[
- tooltipType: "qtip", //tooltip类型,默认使用qtip,但使用前必须先初始化,留意第一行js。也可以使用title。
- toggleGroup: "grouname",//给一组按钮添加开关效果,类似radio的效果,大家自己测试。
- type: "button", //默认button,可以设为submit或reset。
- renderTo: Ext.getBody()//指定显示容器,这里设为body,也可以设为某个div,使用容器id作为标示。
- //handler: function(){Ext.Msg.alert('info','this is handler!')}
- });
- function test(){
- Ext.Msg.alert('onevent', 'this is test function!');
- }
- //以下是两个比较重要的方法,大家自行测试
- //on用于添加instener
- btn.on("mouseover", test);
- //un用于删除listener
- btn.un("mouseover", test);
- //以下是常用事件
- //beforedestroy : ( Ext.Component this )
- //beforehide : ( Ext.Component this )
- //beforerender : ( Ext.Component this )
- //beforeshow : ( Ext.Component this )
- //beforestaterestore : ( Ext.Component this, Object state )
- //beforestatesave : ( Ext.Component this, Object state )
- //click : ( Button this, EventObject e )
- //destroy : ( Ext.Component this )
- //disable : ( Ext.Component this )
- //enable : ( Ext.Component this )
- //hide : ( Ext.Component this )
- //menuhide : ( Button this, Menu menu )
- //menushow : ( Button this, Menu menu )
- //menutriggerout : ( Button this, Menu menu, EventObject e )
- //menutriggerover : ( Button this, Menu menu, EventObject e )
- //mouseout : ( Button this, Event e )
- //mouseover : ( Button this, Event e )
- //render : ( Ext.Component this )
- //show : ( Ext.Component this )
- //staterestore : ( Ext.Component this, Object state )
- //statesave : ( Ext.Component this, Object state )
- //toggle : ( Button this, Boolean pressed )
- //以下是常用方法
- //addClass( string cls ) : void
- //addEvents( Object object ) : void
- //addListener( String eventName, Function handler, [Object scope], [Object options] ) : void
- //applyToMarkup( String/HTMLElement el ) : void
- //cloneConfig( Object overrides ) : Ext.Component
- //destroy() : void
- //disable() : Ext.Component
- //enable() : Ext.Component
- //findParentBy( Function fcn, [Object scope] ) : Array
- //findParentByType( String/Class xtype ) : Container
- //fireEvent( String eventName, Object... args ) : Boolean
- //focus() : void
- //getEl() : Ext.Element
- //getId() : String
- //getItemId() : String
- //getText() : String
- //getXType() : String
- //getXTypes() : String
- //hasListener( String eventName ) : Boolean
- //hasVisibleMenu() : Boolean
- //hide() : Ext.Component
- //hideMenu() : void
- //initComponent() : void
- //isVisible() : void
- //isXType( String xtype, [Boolean&li>
- <a href="#" onclick="Ext.log('Hello from the Ext console.');return false;">debug</a> //启用debug窗口
- </body>
- </html>
文章来自: 本站原创
Tags: extjs js javascript 技术
相关日志:
评论: 0 | 引用: 0 | 查看次数: 4371
发表评论
上一篇
下一篇

