new Ext.form.NumberField({ id: "txtIssuedNum", fieldLabel: '<% = GetLocalResourceObject("WriteAddRecordText") %>', allowDecimals: false, //不允许输入小数 nanText: '<% = GetLocalResourceObject("WriteIntText") %>', //无效数字提示 allowNegative: false, //不允许输入负数 maxValue: 100, //最大值 minValue: 1, //最小值 enableKeyEvents: true, // 要有 listeners: { keyup: function () { var num = Ext.getCmp("txtIssuedNum").getValue(); if (num < 1) return false; var count = ds.getCount(); if (count == num) { return false; } else if (count < num) { var o = num - count; for (var i = 0; i < o; i++) { var iss = new ds.recordType({ ISSBANK: "x", ISSBRANCHBANK: "xx", CARDNUM: "xxx", CARDHOLDER: "xxxx", AMOUNT: 0.00, MERDETAILREFNUM: "xxxx", MERREMARK: "xxxxxx" }); ds.addSorted(iss); } } else { var oo = count - num; for (var i = 0; i < oo; i++) { ds.remove(ds.getAt(count - oo)); } } } } })
change
new Ext.form.NumberField({ id: "txtIssuedNum", fieldLabel: '<% = GetLocalResourceObject("WriteAddRecordText") %>', allowDecimals: false, //不允许输入小数 nanText: '<% = GetLocalResourceObject("WriteIntText") %>', //无效数字提示 allowNegative: false, //不允许输入负数 maxValue: 100, //最大值 minValue: 1, //最小值 enableKeyEvents: true, //可以不要 listeners: { change: function () { var num = Ext.getCmp("txtIssuedNum").getValue(); if (num < 1) return false; var count = ds.getCount(); if (count == num) { return false; } else if (count < num) { var o = num - count; for (var i = 0; i < o; i++) { var iss = new ds.recordType({ ISSBANK: "x", ISSBRANCHBANK: "xx", CARDNUM: "xxx", CARDHOLDER: "xxxx", AMOUNT: 0.00, MERDETAILREFNUM: "xxxx", MERREMARK: "xxxxxx" }); ds.addSorted(iss); } } else { var oo = count - num; for (var i = 0; i < oo; i++) { ds.remove(ds.getAt(count - oo)); } } } } })
添加一个延时触发的例子
var fun; var txt = new Ext.form.TextField({ id: "txt", fieldLabel: "用户名称", enableKeyEvents: true, listeners: { keyup: function () { clearTimeout(fun); fun = setTimeout(function () { var text = Ext.getCmp("txt").getValue(); alert(text); }, 500); } } }); txt.render(Ext.getBody());