1 var textbox = document.forms[0].elements["textbox1"]; 2 3 //文本框忽略所有输入的非数值 4 EventUtil.addHandler(textbox, "keypress", function(event) { 5 event = EventUtil.getEvent(event); 6 var target = EventUtil.getTarget(event); 7 var charCode = EventUtil.getCharCode(event); 8 9 if (!/\d/.test(String.fromCharCode(charCode)) && charCode > 9 && !event.ctrlKey) { 10 EventUtil.preventDefault(event); 11 } 12 });