如果我添加这样如何将点击事件添加到extjs autoel?
xtype: 'component',
autoEl: {
html: '<input type="submit" class="custom_loginbtn" value="Submit" id="login"/>'
}
任何想法按钮如何将点击事件添加到这一点?
问候
如果我添加这样如何将点击事件添加到extjs autoel?
xtype: 'component',
autoEl: {
html: '<input type="submit" class="custom_loginbtn" value="Submit" id="login"/>'
}
任何想法按钮如何将点击事件添加到这一点?
问候
尝试添加监听
listeners: {
render: function(component){
component.getEl().on('click', function(e){
console.log(component);
alert('test');
});
}
}
检查this
您使用的是标准的提交按钮,为什么不使用的xtype按钮? - 它可以为您的点击事件指定一个处理程序。
,因为我需要使用一个CSS样式的按钮,而不是extjs按钮 – 2012-01-04 13:32:15
你看看样式extjs按钮?或使用背景图像? – dbrin 2012-01-04 17:44:35
我尝试申请的yup风格不适用于extjs默认按钮,虽然 – 2012-01-05 19:50:50
xtype : 'component',
itemId : 'submitbtn',
autoEl : {
html : '<input type="submit" class="custom_loginbtn" value="Login" id="login"/>'
},
listeners : {
el : {
delegate : 'input',
click : function()
{
}
}
}
这是最好的方法,注意代替.on()
这是更好地与.mon()
使用管理听众的,当你从可能被损坏的元器件听DOM元素使用
xtype: 'component'
,html: '<input type="submit" class="custom_loginbtn" value="Submit" id="login"/>'
,listeners: {
afterrender: function(inputCmp) {
inputCmp.mon(inputCmp.el, 'click', function(){alert('click!')}, this, {delegate:'input'});
}
,single: true
}
此外,您使用autoEl类似于设置组件的html属性,autoEl中的其他选项允许您操作自动创建的外部标签的类型和属性以包含组件
如果你这样做,而不是你可以把关闭组件本身为<input>
,避免包装<div>
:
xtype: 'component'
,autoEl: {
tag: 'input'
,cls: 'custom_loginbtn'
,type: 'submit'
,value: 'Submit'
}
,listeners: {
afterrender: function(inputCmp) {
// no delegate needed, since inputCmp.el is the <input>
inputCmp.mon(inputCmp.el, 'click', function(){alert('click!')}, this);
}
,single: true
}
小心这一点。您的渲染侦听器将添加一个onClick事件到底层元素,但渲染事件可能会再次触发。 – dbrin 2012-01-03 17:52:46
谢谢。找到了另一种解决方案,我会发布它 – 2012-01-04 13:33:53