Javascript 按钮点击事件 Ext JS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3119152/
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
Button click event Ext JS
提问by roobotta
I have the simple form:
我有简单的形式:
myForm = new Ext.form.FormPanel({
width:'100%',
frame:false,
items: [
new Ext.form.TextArea({
id:'notes',
name: 'notes',
hideLabel: true,
width:350,
height:200
})
],
buttons: [
{
text:"Save",
click: function (b,e) {
alert('x');
}
}
]
});
However I am having trouble getting the click event of the button to work. Do buttons created the following way have the same functionality of doing Ext.Button?
但是,我无法使按钮的点击事件正常工作。按以下方式创建的按钮是否具有与 Ext.Button 相同的功能?
回答by Evan Trimboli
You either need
你要么需要
a) The handler option (a click shortcut)
a) 处理程序选项(单击快捷方式)
new Ext.Button({
handler: function(){
// ....
}
});
b) Event listeners need to be registered in in a listeners block, so
b) 事件监听器需要在监听器块中注册,所以
new Ext.Button({
listeners: {
click: function(){
// ...
}
}
});
A) is preferred.
A) 是首选。

