function onlyNumber(id)
{
var txt = $(id);
if (txt == null) return; //对象不存在 txt.onkeyup = function () {this.value = this.value.replace(/[^0-9.-]/g,"");};
txt.onblur = txt.onkeyup;
txt.onchange = txt.onkeyup;

if (isIE())
{
txt.ondrop = function () {event.dataTransfer.setData("text",event.dataTransfer.getData("text").replace(/[^0-9.-]/g,""));}
txt.onbeforepaste = function () {clipboardData.setData("text",clipboardData.getData("text").replace(/[^0-9.-]/g,""));}
}
}
这个函数只允许输入数字,没有对数字的大小进行限制,你自己改一下就行了

解决方案 »

  1.   

    <input name="name1" type="text" id="name1" size="60" onkeyup="value=value.replace(/[^\d]/g,'')" onblue="check()">
    function check()
    {
        var value  = document.all.name1.value;
        if (praseInt(value)>100)
            document.all.name1.value = 100;
    }
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>无标题页</title>
    </head>
    <body>
    <input name="name1" type="text" id="name1" size="60"> 
    <script>
    var a=/^[1-9]\d*$/g;
    var b=/([^\d]|^0)/g;
    var obj=document.getElementById("name1");
    obj.onkeyup=function()
    {
    this.value=this.value.replace(b,"");
    var str=this.value.match(a);
    if(str!=null){
    if(parseInt(str[0])>100)
    {
    this.value=100;
    }
    else if(parseInt(str[0])<0)
    {
    this.value=0;
    }
    else
    {
    this.value=str[0];
    }}
    }
    </script>
    </body>
    </html>
      

  3.   

    3L onblue="check()"。