keypress事件

 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 });
posted @ 2012-06-03 23:10  小猩猩君  阅读(220)  评论(0编辑  收藏  举报