日期:2014-05-18  浏览次数:20786 次

一个文本框只允许输入数字
一个文本框只允许输入数字,这个应该怎么去做啊?…..大于0  
<input   name= "page "   type= "text "   size= "14 "   maxlength= "14 ">

------解决方案--------------------
<input name= "page " type= "text " size= "14 " maxlength= "14 " id= "tb2 ">

var name=document.getElementById( "tb2 ").value;
var size= document.getElementById( "tb2 ").length;
if(size <0)
{
alert( '长度大于0);
return flase;
}
else if(name.toString()== "NaN ")
{
alert( '请写入数字 ');
return
}
------解决方案--------------------
可以用js 正则表达式应该很简单
------解决方案--------------------
<input name= "page " type= "text " size= "14 " maxlength= "14 " id= "tb2 ">
if(isNaN(document.getElementById( "tb2 ").value))
alert( '请写入数字 ');
------解决方案--------------------
用正则表达式限制只能输入数字:

onkeyup= "value=value.replace(/[^\d]/g, ' ') "

onbeforepaste= "clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[^\d]/g, ' ')) "

------解决方案--------------------
<input name= "page " type= "text " size= "14 " onKeyPress= "return(event.keyCode> =46&&event.keyCode <=57) " style= "ime-mode:Disabled " onbeforepaste= "clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[^\d]/g, ' ')) ">
------解决方案--------------------
conclick= "checkV(); "
function checkV(){
var r = /^\d+$/g;
if(! r.test(document.getElementById( "txt1 ").value) )alert( "false ");
}
------解决方案--------------------
怎么没人用onkeydown的啊,这样输入的时候都只能输入,曾经回答过了这样的问题了
------解决方案--------------------
dd
------解决方案--------------------
function isDigit(theNum){
var theMask = "0123456789 ";
if (isEmpty(theNum)) return(false);
else if(theMask.indexOf(theNum) == -1) return(false);
return(true);
}

------解决方案--------------------
<INPUT type= "text " name= "money " onkeypress= "if (event.keyCode <= 45 || event.keyCode > 57) event.returnValue = false; ">
我项目就用这个。
------解决方案--------------------
用onKeyUp= "value=value.replace(/[^\d|]/g, ' ') "
------解决方案--------------------
function chknum(NUM)
{
var i,j,strTemp;
strTemp= ".0123456789 ";
if ( NUM.length== 0)
return 0
for (i=0;i <NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
return 0;
}
}

return 1;
}
上面的是判断JS
下面是调用JS
function check(){
var mostMoney=document.all( "mostMoney ").value;
if(mostMoney!= " " &&chknum(mostMoney)==0)