本文介绍了阻止用户在文本框中写信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i希望在javascript中创建函数,这可以防止用户在文本框中写字母只允许数字
i找到这一个
function prevent_number(event)
{
var charcode =(event.which)? event.which:event.keycode
if (charcode> 31&&(charcode< 48 || charcode> 57))
{
alert(' 请仅输入数字' );
return false ;
}
else
{
return true ;
}
}
i想知道为什么他说charcode> 31&&(charcode< 48 || charcode> 57)
他们的代码从0到9的数字只是从48到57
解决方案
hi all ,
i want to make function in javascript which can prevent user from writing letters in textbox only allow number
i found this one
function prevent_number(event) { var charcode = (event.which) ? event.which : event.keycode if (charcode >31 &&(charcode<48||charcode >57)) { alert('please enter only number '); return false; } else { return true ; } }
i want to know why he said charcode>31 &&(charcode<48||charcode>57)
the numbers from 0 to 9 their code is just from 48 to 57
解决方案
这篇关于阻止用户在文本框中写信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!