Javascript 如何增加和减少文本字段maxLength
我有一个Javascript 如何增加和减少文本字段maxLength,javascript,extjs,Javascript,Extjs,我有一个textfield,在这里我声明maxLength:15。在focusleave事件中,我添加了更多字符,如,,因此我想增加文本字段的长度 我的代码是: { xtype: 'textfield', name: 'email', fieldLabel: 'Email Address', maxLength: 15 vtype: 'email' // requires value to be a valid email address format,
textfield
,在这里我声明maxLength:15
。在focusleave
事件中,我添加了更多字符,如,
,因此我想增加文本字段的长度
我的代码是:
{
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email Address',
maxLength: 15
vtype: 'email' // requires value to be a valid email address format,
listeners: {
focusleave: function( this, event, eOpts) {
var myVAl = this.Value();
myVAl.toLocaleString({
minimumFractionDigits: 3
});
}
}
}
在这里,如果我放15个字符,然后我想在每三个字符后加上十进制,所以我只得到13个字符,使用完整字符
那么在这种情况下如何增加和减少maxLength
那么如何增加和减少maxLength呢
是的,您可以使用在和事件中进行更改
在这个中,我使用相同的textfield.inputEl
创建了一个演示。希望这将帮助/指导您实现您的要求
代码片段
Ext.application({
name: 'Fiddle',
launch: function () {
function stringInsert(str, n, joinwith) {
var ret = [],
i = 0,
len = str.length;;
for (; i < len; i += n) {
ret.push(str.substr(i, n))
}
return ret.join(joinwith)
};
Ext.create({
xtype: 'form',
title: 'Demo Form',
bodyPadding: 15,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email Address',
vtype: 'email', // requires value to be a valid email address format,
listeners: {
focusenter: function (field) {
var value = field.getValue().replace(/\./g, '');
field.setValue(value);
field.inputEl.dom.maxLength=15;
},
focusleave: function (field, event, eOpts) {
var value = this.getValue(),
newValue = stringInsert(value, 3, '.');
field.inputEl.dom.maxLength=newValue.length;
field.setValue(newValue);
}
}
}]
})
}
});
Ext.application({
名字:“小提琴”,
启动:函数(){
函数stringInsert(str,n,joinwith){
var ret=[],
i=0,
len=str.length;;
对于(;i
Ext.application({
name: 'Fiddle',
launch: function () {
function stringInsert(str, n, joinwith) {
var ret = [],
i = 0,
len = str.length;;
for (; i < len; i += n) {
ret.push(str.substr(i, n))
}
return ret.join(joinwith)
};
Ext.create({
xtype: 'form',
title: 'Demo Form',
bodyPadding: 15,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email Address',
vtype: 'email', // requires value to be a valid email address format,
listeners: {
focusenter: function (field) {
var value = field.getValue().replace(/\./g, '');
field.setValue(value);
field.inputEl.dom.maxLength=15;
},
focusleave: function (field, event, eOpts) {
var value = this.getValue(),
newValue = stringInsert(value, 3, '.');
field.inputEl.dom.maxLength=newValue.length;
field.setValue(newValue);
}
}
}]
})
}
});