我在实现跳转到第几页功能
求一段控制web控件文本框不能为空且只能输入正整数的javascript代码

解决方案 »

  1.   

    输入时只能为正数还是输入完了进行验证
    验证的话就用if textbox1.text.lenght>0 and cint(textbox1.text)>0 and instr(textbox1.text,".")=0 then
    在输入时进行控制应该是没办法的吧?
      

  2.   

    function UpdateSpace()
           {var Num=document.all("TextBox1").value;
     Num=new Number(Num)
     if(Num.toString()=="NaN")
     {
       alert('请输入数字!');
       return false;
     }
    }
      

  3.   

    function checkNum()
    {
    var reg=/^[0-9]*[1-9][0-9]*$/;
    if(window.document.Form1.txtNum.value == "")
    {
    alert("请输入你要跳转的页数。");
    document.Form1.txtNum.focus();
    return false;
    }
    if(reg.test(window.document.Form1.txtNum.value) == false)
    {
    alert('请输入一个大于0的整数!');
    document.Form1.txtNum.focus();
    return false;
    }
    }
      

  4.   

    楼主可以参考以下代码:
    <html>
    <head>
    <title>test</title>
    </head>
    <script language="javascript">
    function alertlength()
    {
    var txt=document.getElementById("dd");
    vTel=txt.value;if(vTel.search(/^[1-9][0-9]{0,}/))
    {
    alert("不正确!");
    }
    else
    {
    alert("正确");
    }
    }
    </script>
    <body>
    <input type="text" name="dd">
    <input type="button" onclick="alertlength()">
    </body>
    </html>
      

  5.   


    我用的是web控件TextBox,名称是:num
    结果提示:Microsoft JScript 运行时错误: 'window.document.Form1.num' 为空或不是对象
    怎么办啊