问个问题,谢谢各位
我现在要对页面表单中的一个值age的值进行检查如果为数字且他的值是1或都2才正确,
其它的非数字 ,不等于1或者不等2的值都不正确,给出提示,下面是我的代码:
function checknumeric(el)
{
//如果含有非字母数字 返回 true
var text1="1234567890";
for(i=0;i<=el.length-1;i++)
{
char1=el.charAt(i);
index=text1.indexOf(char1);
if(index==-1){
return true;//非法
}
//没有
}
return false;
}
if(!checknumeric(document.form1.age))
{
alert("ageasg is not legal");
return false;
}//判断是否是数字
if((document.form1.age.value) >1||(document.form1.age.value)< 0)
{
alert("the age.is not legal");
return false;
}
请问为什么老时提示错误就是输入数字也是错的,比如输入135应该提示the age.is not legal但它总是第一条提示,就是说它执行第一次检查去了,请问该检查函数不对还是调用 方法不对,有请各位高手帮帮忙呀