Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何增加和减少文本字段maxLength_Javascript_Extjs - Fatal编程技术网

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);
                    }
                }
            }]
        })
    }
});