[轉載]ExtJs4 筆記(5) Ext.Button 按鈕

來源:互聯網
上載者:User

標籤:blog   class   c   java   ext   http   

李盼(Lipan)
出處:[Lipan] (http://www.cnblogs.com/lipan/)
著作權聲明:本文的著作權歸作者與部落格園共有。轉載時須註明本文的詳細連結,否則作者將保留追究其法律責任。

 

從本篇開始講基礎控制項,ExtJs對所有的UI控制項都有它自己的一套封裝。本篇要講到的是ExtJs的按鈕。主要包括按鈕事件、帶分割線、帶表徵圖、帶菜單的按鈕,下拉選項式按鈕和按鈕組合等。我們先看看:

預覽

如下是用到的html:

[html]

    <h1>        三種方式實現事件:    </h1>    <div id="div1" class="content">        <ul>            <li id="li1"></li>            <li id="li2"></li>            <li id="li3"></li>        </ul>    </div>    <h1>        帶表徵圖菜單:    </h1>    <div id="div2" class="content">    </div>    <h1>        帶分割線的按鈕</h1>    <div id="div3" class="content">    </div>    <h1>        菜單式按鈕</h1>    <div id="div4" class="content">    </div>    <h1>        按鈕組合</h1>    <div id="div5" class="content">    </div>
一、基本按鈕,三種方式實現按鈕事件

這裡介紹了最基本的按鈕產生代碼,第一個按鈕具備彈起和按下兩種狀態,三個按鈕分別別設定成三種大小。每個按鈕的單擊事件都是通過一種新的實現方式。下面看看Js代碼:

[Js]

    Ext.create("Ext.Button", {        renderTo: Ext.get("li1"),        text: "事件實現1",        allowDepress: true,     //是否允許按鈕被按下的狀態        enableToggle: true,     //是否允許按鈕在彈起和按下兩種狀態中切換        handler: function () {            Ext.Msg.alert("提示", "第一個事件");        },        id: "bt1"    });    Ext.create("Ext.Button", {        renderTo: Ext.get("li2"),        text: "事件實現2",        listeners: { "click": function () {            Ext.Msg.alert("提示", "第二個事件");        }        },        id: "bt2",        scale: ‘medium‘    });    var bt3 = Ext.create("Ext.Button", {        renderTo: Ext.get("li3").dom,        text: "事件實現3",        id: "bt3",        scale: ‘large‘    });    bt3.on("click", function () {        Ext.Msg.alert("提示", "第三個事件");    });

 

二、帶表徵圖菜單

按鈕可以帶表徵圖和菜單,我們可以在配置項裡面配置:

[Js]

    Ext.create("Ext.Button", {        renderTo: Ext.get("div2"),        id: "bt4",        text: "帶菜單帶表徵圖",        iconCls: "add16",        menu:        {            items: [                {                    text: ‘選項1‘                }, {                    text: ‘選項2‘                }, {                    text: ‘選項3‘,                    handler: function () {                        Ext.Msg.alert("提示", "來自菜單的訊息");                    }                }            ]        }    }).showMenu();    Ext.create("Ext.Button", {        renderTo: Ext.get("div2"),        id: "bt5",        text: "標下菜單",        iconCls: "add16",        iconAlign: ‘top‘,        menu:        {            items: [                {                    text: ‘選項1‘                }, {                    text: ‘選項2‘                }, {                    text: ‘選項3‘,                    handler: function () {                        Ext.Msg.alert("提示", "來自菜單的訊息");                    }                }            ]        },        arrowAlign: ‘bottom‘    });

 

三、帶分割線的按鈕

注意的地方:分割線的按鈕來自於類Ext.SplitButton

[Js]

    Ext.create("Ext.button.Split", {        renderTo: Ext.get("div3"),        text: "右表徵圖下菜單",        iconCls: "add16",        iconAlign: ‘right‘,        menu:        {            items: [                {                    text: ‘選項1‘                }, {                    text: ‘選項2‘                }, {                    text: ‘選項3‘,                    handler: function () {                        Ext.Msg.alert("提示", "來自菜單的訊息");                    }                }            ]        },        arrowAlign: ‘bottom‘    });

 

四、菜單式按鈕

按鈕式菜單Ext.CycleButton與下拉不同的是,它具備選中狀態,當選中下拉項時,選中文本會相應變化。

[Js]

    Ext.create(‘Ext.button.Cycle‘, {        renderTo: Ext.get("div4"),        showText: true,        prependText: ‘請選擇:‘,        menu:        {            items: [{                text: ‘選項1‘,                checked: true            }, {                text: ‘選項2‘            }, {                text: ‘選項3‘            }]        },        changeHandler: function (btn, item) {            Ext.Msg.alert(‘修改選擇‘, item.text);        }    });

 

四、按鈕組合

定義了一組按鈕,並可以控制按鈕排版。

[Js]

   Ext.create("Ext.ButtonGroup",{        renderTo: Ext.get("div5"),        title: "按鈕組合",        columns: 3,        //defaultType:‘splitbutton‘,        items: [{            text: ‘按鈕1‘,            iconCls: ‘add16‘,            scale: ‘large‘,            rowspan: 2        }, {            text: ‘按鈕2‘, iconCls: ‘add16‘, rowspan: 2, scale: ‘large‘        }, {            text: ‘按鈕3‘, iconCls: ‘add16‘        }, {            xtype: ‘splitbutton‘, text: ‘分割線按鈕‘, iconCls: ‘add16‘, menu: [{ text: ‘菜單1‘}]        }]    });

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.