2个回答
2013-07-30
展开全部
<input onkeyup="value=value.replace(/[^1234567890-]+/g,'')">
<input onkeyup="value=value.replace(/[ -~]/g,'')">
<input onkeyup="value=value.replace(/[ -~]/g,'')">
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-30
展开全部
<input type="text" onkeydown="inputOnlyNum(event);" onkeypress="checkIfNum(event);">
<script language="javascript">
var keyIsNum = true;
function inputOnlyNum(myEvent)
{
var keys=myEvent.keyCode;
if (!((keys>=48&&keys<=57)||(keys>=96&&keys<=105)||( keys==8 )||(keys==46)||(keys==37)||(keys==39)||(keys==13)||(keys==229)
))
{
keyIsNum = false;
}
else
{
keyIsNum = true;
}
}
function checkIfNum(myEvent)
{
if(!keyIsNum)
{
if(document.all)
myEvent.returnValue=false;//ie
else
myEvent.preventDefault();//ff
}
}
</script>
<script language="javascript">
var keyIsNum = true;
function inputOnlyNum(myEvent)
{
var keys=myEvent.keyCode;
if (!((keys>=48&&keys<=57)||(keys>=96&&keys<=105)||( keys==8 )||(keys==46)||(keys==37)||(keys==39)||(keys==13)||(keys==229)
))
{
keyIsNum = false;
}
else
{
keyIsNum = true;
}
}
function checkIfNum(myEvent)
{
if(!keyIsNum)
{
if(document.all)
myEvent.returnValue=false;//ie
else
myEvent.preventDefault();//ff
}
}
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询