惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
S
SegmentFault 最新的问题
D
Docker
博客园 - 司徒正美
雷峰网
雷峰网
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
MongoDB | Blog
MongoDB | Blog

博客园 - lwjacky

SQL提高查询效益之in、not in、between、like等条件讲述 sqlserver查询数据的所有表名和行数 Extjs4---Cannot read property 'addCls' of null ExtJs4.1实现数据缓存 Sql 脚本文件太大 系统操作日志设计 一种简单的直观的高效的权限设计 ExtJs 常用方法 属性 C#农历类 通过C#使用googleAPI SQL SERVER 如何批量修改表和存储过程的架构 HTML特殊转义字符列表 - lwjacky - 博客园 extjs3.0 修正 ie 与 firefox字体显示差异的补丁 C#实现QQ接口软件--QQ的HTTP接口协议探究 二次开发WinWebMail邮件系统接口 C#实现汉字转换为拼音缩写的代码 C#实现将汉字转化为拼音的代码 extjs IE8下datefield的width问题 自己的工具箱(Toolkit)
ExtJS中如何给Label添加click事件
lwjacky · 2009-11-12 · via 博客园 - lwjacky

     ExtJS中Ext.form.Label默认是没有click事件的,但由于项目需要,要求给label添加一些其它的事件,本文提供两种方法对这个class进行扩展,方法如下:

方法1:

Ext.onReady(function() {
   var p = new Ext.ux.MyPanel({
      renderTo : document.body
     });
  });
Ext.ux.MyPanel = Ext.extend(Ext.Panel, {
   initComponent : function() {
    Ext.apply(this, {
       width : 200,
       height : 200,
       items : [{
        xtype : 'label',
        id : 'mylabel1',
        html : 'Label 1',
        listeners : {
         render : function() {//渲染后添加click事件
          Ext.fly(this.el).on('click',
            function(e, t) {
             // do stuff
             alert('Hi');
            });
         },
         scope : this
        }
       }]
      });
    Ext.ux.MyPanel.superclass.initComponent.call(this);
   }
  });

方法2:

Ext.onReady(function() {
            //在渲染后添加click事件
   Ext.form.Label.prototype.afterRender = Ext.form.Label.prototype.afterRender
     .createSequence(function() {
        this.relayEvents(this.el, ['click']);
       });//这一段一定要放在label之前
   var tempPanel = new Ext.Panel({
      layout : 'fit',
       renderTo : document.body,
      items : [{
         xtype : 'label',
         text : 'label click',
         listeners : {
          'click' : {
           fn : function(field) {
            alert("Hi");
           },
           scope : this
          }
         }
        }]
     });
  });