javascript中某些字符的按键事件 编号:
这是我的文本框…我在按键上应用了一个函数…这是函数javascript中某些字符的按键事件 编号:,javascript,Javascript,这是我的文本框…我在按键上应用了一个函数…这是函数 number:<input type="text" name="number" onkeypress='return numbersonly(event)' /> 功能编号仅限(e){ var unicode=e.charCode?e.charCode:e.keyCode if(unicode!=8){//如果该键不是退格键(我们应该允许) if(unicode57&&unicode!=65)//如果不是数字 返回false//
number:<input type="text" name="number" onkeypress='return numbersonly(event)' />
功能编号仅限(e){
var unicode=e.charCode?e.charCode:e.keyCode
if(unicode!=8){//如果该键不是退格键(我们应该允许)
if(unicode57&&unicode!=65)//如果不是数字
返回false//禁用按键
}
}
使用此按键功能,用户只能输入0-9之间的数字。现在我想要的是,它应该只接受一个字母表,该字母表的ascii数为65…但当我处于应用状态时,它不会接受字母表,所以任何人都可以帮我解决此问题吗???
+
符号unicode是43而不是107
尝试:
功能编号仅限(e){
var unicode=e.charCode?e.charCode:e.keyCode;
if(unicode!=8){//如果该键不是退格键(我们应该允许)
if((unicode57)&&(unicode!=65)&&&(unicode!=43))//如果不是数字
返回false//禁用按键
}
}
unicode 65是A。它似乎对我有用。我希望它接受+号,它不接受dat…你能告诉我为什么吗??
<script type="text/javascript">
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57&&unicode!=65) //if not a number
return false //disable key press
}
}
</script>
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode;
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if ((unicode<48||unicode>57)&&(unicode!=65)&&(unicode!=43)) //if not a number
return false //disable key press
}
}