extjs 4:点击事件上的按钮无法正常工作

时间:2013-02-16 06:31:57

标签: javascript extjs extjs4

{
xtype: 'button',
id : 'btnShowImage',
text : 'Show Image On List',
scale   : 'large',
width : 200,
margin : '0 0 0 180',   
}

var ShowImgBtn = Ext.get('btnShowImage');
    ShowImgBtn.on('click', function(){
    alert('hi');
    });

问题

怎么来不行?有什么问题?应该可以工作。

2 个答案:

答案 0 :(得分:0)

您的代码正在运行:

Ext.onReady(function() {
    Ext.create('Ext.Button', {
        renderTo: Ext.getBody(),
        id : 'btnShowImage',
        text : 'Show Image On List',
        scale   : 'large',
        width : 200,
        margin : '0 0 0 180'
    });

    var ShowImgBtn = Ext.get('btnShowImage');
    ShowImgBtn.on('click', function(){
        alert('hi');
    });
});

<强> http://jsfiddle.net/ht4UL/

可以是你的按钮没有渲染吗?

答案 1 :(得分:0)

将代码编辑为

Ext.getCmp('btnShowImage')  

这是有效的。