最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add click event on Extjs 4 label - Stack Overflow

programmeradmin3浏览0评论

I try to add click event on label in extjs4 but not working

Ext.onReady(function() {

    var ResetLabel = new Ext.form.Label({
        id:'ResetLabel',
        text: 'click it',
        renderTo : document.body                                

    });
    alert(Ext.getCmp('ResetLabel').id);

    Ext.getCmp('ResetLabel').on('click',function(){

        alert("message");
    });

});

How to add event on a label?

I try to add click event on label in extjs4 but not working

Ext.onReady(function() {

    var ResetLabel = new Ext.form.Label({
        id:'ResetLabel',
        text: 'click it',
        renderTo : document.body                                

    });
    alert(Ext.getCmp('ResetLabel').id);

    Ext.getCmp('ResetLabel').on('click',function(){

        alert("message");
    });

});

How to add event on a label?

Share Improve this question edited Oct 24, 2019 at 11:30 Brian Tompsett - 汤莱恩 5,88372 gold badges61 silver badges133 bronze badges asked Sep 15, 2011 at 10:01 jayeshjayesh 2,4927 gold badges44 silver badges80 bronze badges 2
  • Are there any Javascript errors? Can you paste all the code and not just a couple of line? – Paul Grime Commented Sep 15, 2011 at 10:06
  • i describe code which also not working with on click event and its not give any error – jayesh Commented Sep 15, 2011 at 11:15
Add a comment  | 

6 Answers 6

Reset to default 5

this code is working in Extjs 4

Ext.onReady(function() {

    var ResetLabel = new Ext.form.Label({
        id:'ResetLabel',
        text: 'click it',
        renderTo : document.body                                

    });
    alert(Ext.getCmp('ResetLabel').getEl());

    Ext.getCmp('ResetLabel').getEl().on('click',function(){

        alert("message");
    });

});
{ 
    xtype: 'label',
    listeners: { 
       element: 'el',
       click: function () { alert(); }
    }
}

try this:

Ext.onReady(function() { 

var ResetLabel = new Ext.form.Label({ 
    id:'ResetLabel', 
    text: 'click it', 

listeners: {
   click: function(){ 
           alert("message"); 
       }
},

    renderTo : document.body                                 

}); 

alert(Ext.getCmp('ResetLabel').id); 


}); 

Yep doesn't work for me either, tried all the examples...

check that, this worked

    var ResetLabel = new Ext.form.Label({
        id:'ResetLabel',
        text: 'click it'

    });
    Ext.onReady(function() {
        Ext.getCmp('ResetLabel').getEl().on('click',function(){
            alert("message");
        });
    });

I am adding the ResetLabel to my panel.

I'm working on an old code-base on top of ExtJS 3.4 and the following worked for me. I guess it should work for higher versions as well.

new Ext.form.Label({
   "html": "Halp!",
   "listeners": {

       /* We are going to assing the click event right after the element has rendered */
       "afterrender": function () {

           this.getEl().on( "click", function () {
               console.log( "Clicked!" );
           });
       }
    }
});

I like it shorter to get the idea quicker:

// Adding abcent label event through its dom-structure:
myLabel.getEl().on(
  "click",
  onClickMyLabel);
发布评论

评论列表(0)

  1. 暂无评论