转自:http://www.cnblogs.com/lipan/archive/2011/12/13/2274797.html

从本篇开始讲基础控件,ExtJs对所有的UI控件都有它自己的一套封装。本篇要讲到的是ExtJs的按钮。主要包括按钮事件、带分割线、带图标、带菜单的按钮,下拉选项式按钮和按钮组合等。我们先看看效果图:

预览

如下是用到的html:

[html]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<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]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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'}]
     }]
 });

89. Ext.Button 按钮的更多相关文章

  1. [转载]ExtJs4 笔记(5) Ext.Button 按钮

    作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...

  2. ExtJs4 笔记(5) Ext.Button 按钮

    id="li2"></li> <li id="li3"></li> </ul> </div> ...

  3. Extjs.Button 按钮

    Extjs  Button 的简单使用 ,同时调用Ajax服务 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xh ...

  4. ext button 属性

    var buttonName = new Ext.Button({               id:"buttonName",               text:" ...

  5. button 按钮,结合onclick事件,验证和提交表单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 如何在MFC界面开发中响应Button按钮的Down和Up事件

    通过尝试有两种方案可以解决这个问题,第一种方案是通过PreTranslateMessage函数在调度消息之前对消息类型进行筛选,第二种方案是重载CButton类,在重载后的类CForTestButto ...

  7. 遭遇input与button按钮背景图失效不显示的解决办法

    笔者从事网页前端代码页面工程师已有多年,作为一个网页重构人员常常会遇到一些莫名其妙的DIV+CSS(正确的说法是XHTML+CSS)在 IE.FireFox火狐. 谷歌浏览器CHROME.苹果浏览器S ...

  8. button按钮

    button按钮只加类名不加type时,点击此按钮页面会刷新

  9. Unity3D NGUI 给button按钮添加单间事件

    Unity3D中, NGUI 给button按钮添加单间事件的方法很多,在这里只给推荐一种比较常用的方法. 推荐方法:使用UIListener. 1.给button组价添加上UIListener.选择 ...

随机推荐

  1. 从JavaScript的单线程执行说起

    先看一段代码: 1 2 3 4 5 setTimeout(function(){     alert("a"); }, 0); while(1); alert("b&qu ...

  2. k[原创]Faster R-CNN论文翻译

    物体检测论文翻译系列: 建议从前往后看,这些论文之间具有明显的延续性和递进性. R-CNN SPP-net Fast R-CNN Faster R-CNN Faster R-CNN论文翻译   原文地 ...

  3. Android 双屏异显

    android双屏是克隆模式,如果要在第二屏幕显示不同内容,需要自定义一个Presentation类 1.先设置权限 (刚开始折腾很久没有效果,后来发现是没设置权限) <!-- 显示系统窗口权限 ...

  4. 初学者怎么才能快速学会Python?

    提起对Python的印象,除了全能之外恐怕就是简单易学了.很多人都在推荐新手学Python入门,毕竟语法简单.语句简洁,所谓“人生苦短我用Python”绝不是一句空话.不过也不能忽视一点:Python ...

  5. Ansible 利用playbook批量部署Nginx

    我这里直接部署的,环境已经搭建好,如果不知道的小伙伴可以看上一遍ansible搭建,都写好了,这里是根据前面环境部署的 192.168.30.21     ansible 192.168.30.25  ...

  6. 【GC】

    using 语句适用于清理单个非托管资源的情况,而多个非托管对象的清理最好以 try-finnaly 来实现,因为嵌套的 using 语句可能存在隐藏的 Bug.内层 using 块引发异常时,将不能 ...

  7. sysbench_mysql

    ref http://seanlook.com/2016/03/28/mysql-sysbench/ 测试 当执行下面这个sysbench测试mysql的时候,你不知道的可能可能是: 这到底是在测试读 ...

  8. 笔记,js对象浅析

    学习笔记, 来源:http://www.cnblogs.com/zuiyirenjian/p/3535126.html 作者:醉意人间  此外,关于自运行函数可参考  http://benalman. ...

  9. POJ1161——The Suspects

    POJ1161——The Suspects   The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 48 ...

  10. vue数据绑定源码

    思路分析 数据的双向绑定,就是数据变化了自动更新视图,视图变化了自动更新数据,实际上视图变化更新数据只要通过事件监听就可以实现了,并不是数据双向绑定的关键点.关键还是数据变化了驱动视图自动更新. 所有 ...