解决方案 »

  1.   

    <input type="text"onkeyup="this.value=this.value.replace(/[^01]/g,'');">定义一个函数
    function abc(){
        GoTop(); 
        location.href='zhuce.jsp';
    }onclick = "abc();"
      

  2.   


    function checkIn(inVal){
    var _p = /^0|0.([0-9]*)|1$/;
    if(!_p.test(inVal)){
    alert("请输入0-1之间的数字,包括0以及1.");
    return false;
    }else{
    alert("格式正确");
    return true;
    }
    }
    function _onclick(){
    GoTop(); 
    location.href='zhuce.jsp';
    }
    <input type="text" onblur="javascript:checkIn(this.value);"/>
    <input type="button" value="Click Me" onclick="java.script:_onclick();"/>
      

  3.   

    sorry,之前验证不充分。
    请将上述的checkIn方法变更为function checkIn(inVal){
    if(!(/^0\.{0,1}\d*[1-9]$/.test(inVal) || /^[0-5]$/.test(inVal))){
    alert("请输入0-1之间的数字,或者0-5的正整数(包括0和5)。");
    return false;
    }else{
    alert("格式正确");
    return true;
    }
    }
      

  4.   

    /^0\.{0,1}\d*[1-9]$/.test(inVal)用于验证0-1之间的小数点。
    /^[0-5]$/.test(inVal)用于验证0-5之间的正整数,包括0和1的。小数验证和整数验证貌似不能写在同一个正则表达式中的。