Javascript 问题:验证输入字段。(js)

Javascript 问题:验证输入字段。(js),javascript,Javascript,我需要validInput函数来检查输入的所有输入是否都是数字字符/ 问题是当第一个if语句返回true时,函数似乎跳过了输入检查。 例如,如果我为input1输入1,那么为input2输入“a”,为input3输入-3,函数将返回true并显示结果 html: 起始编号: 结束号码: 步骤: 陈列柜 js: 功能播放按钮(){ run(); if(validInput()){ showResult(); } }; 函数validInput(){ var x=document.get

我需要validInput函数来检查输入的所有输入是否都是数字字符/ 问题是当第一个if语句返回true时,函数似乎跳过了输入检查。
例如,如果我为input1输入1,那么为input2输入“a”,为input3输入-3,函数将返回true并显示结果

html:

起始编号:

结束号码:
步骤: 陈列柜
js:

功能播放按钮(){
run();
if(validInput()){
showResult();
}  
};
函数validInput(){
var x=document.getElementById(“input1”).value;
var y=document.getElementById(“input2”).value;
var z=document.getElementById(“input3”).value;
如果((x==)| |(isNaN(x))| |(xMohit是正确的

按如下所示更改函数:

function validInput(){
            var x = document.getElementById("startingNum").value;
            var y = document.getElementById("endingNum").value;
            var z = document.getElementById("step").value;
            if((x == "")||(isNaN(x))||(x <= 0)){
                alert("Please enter positive numberic character only.");
                return false;
            }
            if((y == "")||(isNaN(y))||(y <= 0)){
                alert("Please enter positive numberic character only.");
                return false;
            }
            if((z == "")||(isNaN(z))||(z <= 0)){
                alert("Please enter positive numberic character only.");
                return false;
            }                
            return true;    
        };
函数validInput(){
var x=document.getElementById(“startingNum”).value;
var y=document.getElementById(“endingNum”).value;
var z=document.getElementById(“步骤”).value;
如果((x==)| |(isNaN(x))| |(xMohit是正确的

按如下所示更改函数:

function validInput(){
            var x = document.getElementById("startingNum").value;
            var y = document.getElementById("endingNum").value;
            var z = document.getElementById("step").value;
            if((x == "")||(isNaN(x))||(x <= 0)){
                alert("Please enter positive numberic character only.");
                return false;
            }
            if((y == "")||(isNaN(y))||(y <= 0)){
                alert("Please enter positive numberic character only.");
                return false;
            }
            if((z == "")||(isNaN(z))||(z <= 0)){
                alert("Please enter positive numberic character only.");
                return false;
            }                
            return true;    
        };
函数validInput(){
var x=document.getElementById(“startingNum”).value;
var y=document.getElementById(“endingNum”).value;
var z=document.getElementById(“步骤”).value;

如果我已经修改了你的代码,请修改代码

function playButton(){
        run();
        if (validInput()){
            showResult();
        }  
    };

   function validInput(){
        var x = document.getElementById("input1").value;
        var y = document.getElementById("input2").value;
        var z = document.getElementById("input3").value;
        if((x == "")||(isNaN(x))||(x <= 0)){
            alert("Please enter positive numberic character only.");
            return false;
        }
        if((y == "")||(isNaN(y))||(y <= 0)){
            alert("Please enter positive numberic character only.");
            return false;
        }
        if((z == "")||(isNaN(z))||(z <= 0)){
            alert("Please enter positive numberic character only.");
            return false;
        }                
        return true;    
    };
功能播放按钮(){
run();
if(validInput()){
showResult();
}  
};
函数validInput(){
var x=document.getElementById(“input1”).value;
var y=document.getElementById(“input2”).value;
var z=document.getElementById(“input3”).value;

如果我已经修改了你的代码,请修改代码

function playButton(){
        run();
        if (validInput()){
            showResult();
        }  
    };

   function validInput(){
        var x = document.getElementById("input1").value;
        var y = document.getElementById("input2").value;
        var z = document.getElementById("input3").value;
        if((x == "")||(isNaN(x))||(x <= 0)){
            alert("Please enter positive numberic character only.");
            return false;
        }
        if((y == "")||(isNaN(y))||(y <= 0)){
            alert("Please enter positive numberic character only.");
            return false;
        }
        if((z == "")||(isNaN(z))||(z <= 0)){
            alert("Please enter positive numberic character only.");
            return false;
        }                
        return true;    
    };
功能播放按钮(){
run();
if(validInput()){
showResult();
}  
};
函数validInput(){
var x=document.getElementById(“input1”).value;
var y=document.getElementById(“input2”).value;
var z=document.getElementById(“input3”).value;

如果你的错误很小你在比较你的错误很小你在比较打字:
if((z==)| |(isNaN(x))| |(x))| |(x)我说不出话来……请把我投下地狱,这样我下次会记得这句话。打字:
if((z==)|(isNaN(x))||(x我说不出话来……请把我投下地狱,这样下次我会记得这件事。
           if((y == "")||(isNaN(y))||(y <= 0)){
                alert("Please enter positive numberic character only.");
                return false;
            }

           if((z == "")||(isNaN(z))||(z <= 0)){
                alert("Please enter positive numberic character only.");
                return false;
            }