javascript 如何将 Click 事件添加到 Ext.Img?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9664609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:23:11  来源:igfitidea点击:

How can I add Click Event to Ext.Img?

javascriptextjsextjs4

提问by LostCode

How can I add Click Event to Ext.Img?

如何将 Click 事件添加到 Ext.Img?

var paddleItem = new Ext.Img({
    xtype : 'image',
    src : "lib/Image/Paddle.png",
    x : 200,
    y : 300,
    draggable : true,
    index : 0,
    id : 'paddleItem',
    listeners : {
        click : function(){
            Ext.Msg.alert("Message");
        }
    },
    renderTo : Ext.getBody()
});

This is My Code, but it didn't Work.

这是我的代码,但没有用。

Please Get me some Advice..

请给我一些建议..

回答by Evan Trimboli

Bind it on the underlying element:

将其绑定在底层元素上:

var paddleItem = new Ext.Img({
    src: "lib/Image/Paddle.png",
    x: 200,
    y: 300,
    draggable: true,
    index: 0,
    id: 'paddleItem',
    listeners: {
        el: {
            click: function() {
                Ext.Msg.alert("Message");
            }
        }
    },
    renderTo: Ext.getBody()
});