为什么for循环不做下去了,是否与return有关?

零基础学编程by学哥 2001-06-19 04:31:00
function presubmit()
{
var a=document.form1.ptgs.value;
if (isNumeric(a))
{
if (a.charAt(0)=='.')
{
alert("The geshu Number can not be . !");
return false;
}
}
else
{
document.form1.ptgs.focus()
alert("The Number :"+a+" is not a number!");
return false;
}
var b="";
for(var i=0;i<document.form1.length;i++)
{
if((document.form1.elements[i].type).toLowerCase()=="text")
{
if (((((i-11)%12)==5)||(((i-11)%12)==6)||(((i-11)%12)==7)||(((i-11)%12)==8)||(((i-11)%12)==9))&&(i>10))
{
alert(i);
if(document.form1.elements[i].value!="")
{
b=document.form1.elements[i].value;
if (b.length>0)
{
if (isNumeric(b))
{
if (isinfanwei(b))
{
}
else
{
document.form1.elements[i].focus()
return false;
}
}
else
{
document.form1.elements[i].focus()
alert("The Number :"+b+" is not a number!");
return false;
}
}
}
}
}
}
return true;
}
中间for循环做了第一次就不做了.
...全文
179 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2001-06-20
  • 打赏
  • 举报
回复
可以试验一下嘛!
  • 打赏
  • 举报
回复
如果str是整数,好象 var newnum=str.split(".") 就会出错误?
  • 打赏
  • 举报
回复
找到了 var newnum=www.split(".")
应该是 var newnum=str.split(".")
  • 打赏
  • 举报
回复
function isinfanwei(str)
{
var newnum=www.split(".")
if(newnum[0].length>3)
{
alert("The integer part length of the number:"+str+" is more than 3!");
return false;
}
if(newnum[1].length>2)
{
alert("The decimal part length of the number:"+str+" is more than 2!");
return false;
}
return true;
}
这段程序有错,不知道错在哪里?
  • 打赏
  • 举报
回复
function isNumeric(str){
var i=0;
var j=0;
while(i<=str.length-1){
str1=str.charAt(i);
if (str1=='.'){
if ((j>0)||(i==0)||(i==(str.length-1)))
return false;
j=j+1;
}
else if(isNaN(parseInt(str1))==true) return false;
i=i+1;}
return true;
}
function isinfanwei(str)
{
var newnum=www.split(".")
if(newnum[0].length>3)
{
alert("The integer part length of the number:"+str+" is more than 3!");
return false;
}
if(newnum[1].length>2)
{
alert("The decimal part length of the number:"+str+" is more than 2!");
return false;
}
return true;
}
是我自己写的也在javascript里.
孟子E章 2001-06-19
  • 打赏
  • 举报
回复
用isNaN ()
孟子E章 2001-06-19
  • 打赏
  • 举报
回复
isNumeric () javascript了好象没有这个方法!!
孟子E章 2001-06-19
  • 打赏
  • 举报
回复
if (isNumeric(b))里的返回值只是if的条件,决定程序块的执行,造成你的问题的应该在if里的语句块里!
  • 打赏
  • 举报
回复
没法全贴,还有很多jsp+ejb的东西.
我怀疑在做if (isNumeric(b))的时候,因为isNumeric会有return,则function presubmit()也同时return了???
孟子E章 2001-06-19
  • 打赏
  • 举报
回复
应该有关!把你的代码贴全了吧!可以调试啊!

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧