在extjs中对Textfield使用模糊会导致错误
我是extjs新手。我使用的是extjs-4.1.0,我有一个textfield,我希望在它的blur事件中调用trim方法。我的代码在mozilla firefox上运行良好,但会导致javascript错误,当文本框失去焦点时,IE上的Object不支持此属性或方法。 有没有其他方法来处理IE中的模糊事件 请在下面找到我的代码:在extjs中对Textfield使用模糊会导致错误,extjs,extjs4,Extjs,Extjs4,我是extjs新手。我使用的是extjs-4.1.0,我有一个textfield,我希望在它的blur事件中调用trim方法。我的代码在mozilla firefox上运行良好,但会导致javascript错误,当文本框失去焦点时,IE上的Object不支持此属性或方法。 有没有其他方法来处理IE中的模糊事件 请在下面找到我的代码: { flex:1, xtype:'textfield', fieldLabel: 'Name', a
{
flex:1,
xtype:'textfield',
fieldLabel: 'Name',
allowBlank: false,
maxLength: 50,
name: 'name',
maskRe: /[a-zA-Z\s]+$/,
validator: function(v) {
if(!(/[a-zA-Z\s]+$/.test(v))){
return "This Field should be in alphabets";
}
return true;
},
listeners: {
render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'Format: John/John Kelvin'
})
},
blur: function(d) {
var newVal = d.getValue().trim();
d.setValue(newVal);
}
}
}
我把监听器放在一个控制器中,它在IE中似乎工作得很好
Ext.define('BM.controller.FormControl', {
extend: 'Ext.app.Controller',
views: [
'MyForm'
],
init: function() {
if (this.inited) {
return;
}
this.inited = true;
this.control({
'my-form > field': {
blur: this.outOfFocus
}
});
},
outOfFocus: function(field, event) {
var newVal = field.getValue().trim();
field.setValue(newVal);
}
});
我把监听器放在一个控制器中,它在IE中似乎工作得很好
Ext.define('BM.controller.FormControl', {
extend: 'Ext.app.Controller',
views: [
'MyForm'
],
init: function() {
if (this.inited) {
return;
}
this.inited = true;
this.control({
'my-form > field': {
blur: this.outOfFocus
}
});
},
outOfFocus: function(field, event) {
var newVal = field.getValue().trim();
field.setValue(newVal);
}
});
我的猜测是,这与模糊无关,实际上field.getValue在某些情况下不是字符串,例如null、numeric或类似的字符串。尝试替换var newVal=field.getValue.trim 与
我的猜测是,这与模糊无关,实际上field.getValue在某些情况下不是字符串,例如null、numeric或类似的字符串。尝试替换var newVal=field.getValue.trim 与
当文本字段为空时,浏览器IE 7/8将文本字段值d.getValue返回为NULL,因此对trim的方法调用失败,因为未创建有效对象 以下解决方案适用于所有浏览器:
this.setValue(Ext.util.Format.trim(this.getValue()));
当文本字段为空时,浏览器IE 7/8将文本字段值d.getValue返回为NULL,因此对trim的方法调用失败,因为未创建有效对象 以下解决方案适用于所有浏览器:
this.setValue(Ext.util.Format.trim(this.getValue()));
在结束括号}]之前,我还检查了一个额外的逗号,IE讨厌它,但似乎不起作用。我还检查了结束括号}之前的额外逗号,IE讨厌它,但似乎不起作用