javascript 如何在 Extjs 4 标签上添加点击事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7429078/
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
How to add click event on Extjs 4 label
提问by jayesh
I try to add click event on label in extjs4 but not working
我尝试在 extjs4 中的标签上添加点击事件但不起作用
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?
如何在标签上添加事件?
回答by jayesh
this code is working in Extjs 4
此代码适用于 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");
});
});
回答by obenjiro
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);
});
回答by hijeane
{ xtype: 'label', listeners: { element: 'el', click: function () { alert(); } } }
回答by user1346730
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.
我正在将 ResetLabel 添加到我的面板中。
回答by Mahdi
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.
我正在处理 ExtJS 3.4 之上的旧代码库,以下内容对我有用。我想它也应该适用于更高版本。
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!" );
});
}
}
});
回答by Zon
I like it shorter to get the idea quicker:
我喜欢它更短以更快地获得想法:
// Adding abcent label event through its dom-structure:
myLabel.getEl().on(
"click",
onClickMyLabel);