简单的例子,异词类推!!!<script>
ptt0101="text1value"
ptt0102="text2value"
ptt0103="text3value"
ptt0104="text4value"
ptt0105="text5value"
var zu=new Array([ptt0101,ptt0102,ptt0103,ptt0104,ptt0105],["ptt0201","ptt0202","ptt0203","ptt0204","ptt0205"])
for(var i=0;i<2;i++)
{
for(var j=0;j<5;j++)
alert(zu[i][j])
}
</script>
ptt0101="text1value"
ptt0102="text2value"
ptt0103="text3value"
ptt0104="text4value"
ptt0105="text5value"
var zu=new Array([ptt0101,ptt0102,ptt0103,ptt0104,ptt0105],["ptt0201","ptt0202","ptt0203","ptt0204","ptt0205"])
for(var i=0;i<2;i++)
{
for(var j=0;j<5;j++)
alert(zu[i][j])
}
</script>
ptt0101="text1value"
ptt0102=""
ptt0103="text3value"
ptt0104="text4value"
ptt0105="text5value"
var zu=new Array([ptt0101,ptt0102,ptt0103,ptt0104,ptt0105],["ptt0201","ptt0202","ptt0203","ptt0204","ptt0205"])
for(var i=0;i<2;i++)
{
for(var j=0;j<5;j++)
if(zu[i][j]=="")
alert("老天,数组["+i+"]["+j+"] 为空啊!!!")
}
</script>
关键是var s=document.form1.ptt0101.value这样写120行的话是可以的,但是能否在for循环中用一句做到呢?
刚才一个问题已经给你加分了,希望这个问题你能帮我搞定,谢谢.
在jsp里是可以用循环输出的!!验证的工作在客户端,与此无关,关键是你的变量名起的适合用循环来处理即可!
var b=0;
<%
for (int p=0;p<24;p++)
{
for (int j=0;j<5;j++)
{
out.println("b=document.form1.ptt"+p+j+".value;");
}
}
%>
</script>是否这样?
<input name=ptt0101 value="测试">
<input name=ptt0102>
<input name=ptt0103>
<input name=ptt0104>
<input name=ptt0105>
<input name=ptt0201>
<input name=ptt0202>
<input name=ptt0203>
<input name=ptt0204>
<input name=ptt0205>
</form><script>
for(var i=0;i<document.mxh.length;i++)
if(document.mxh.elements[i].value!="")
alert("第"+eval(i+1)+"个文本框不为空啊")
</script>
for(var i=0;i<document.mxh.length;i++)
if (document.mxh.elements[i]==INPUTTEXT)
if(document.mxh.elements[i].value!="")
alert("第"+eval(i+1)+"个文本框不为空啊")
</script> if (document.mxh.elements[i]==INPUTTEXT)
这里判断是否为text类型,怎么写?
<input name=ptt0101 value="测试">
<input name=ptt0102>
<input name=ptt0103>
<input name=ptt0104>
<input name=ptt0105><input name=ptt0201 value="测试">
<input name=ptt0202>
<input name=ptt0203>
<input name=ptt0204>
<input name=ptt0205><input type=button value="检验数据" onclick="test()">
</form><script>function test(){
for(var i=0;i<document.mxh.length;i++)
{
if((document.mxh.elements[i].type).toLowerCase()=="text")
{
if(document.mxh.elements[i].value!="")
alert("第 "+eval(i+1)+" 个表单元素不为空啊 , 其余为空!!!!")
}
}
}
</script>可以检验所有的text!
<input name=ptt0101 value="测试">
<input name=ptt0102>
<input name=ptt0103>
<input name=ptt0104>
<input name=ptt0105>
<input type=button value="检验数据" onclick="test()">
<input type=button value="检验数据" onclick="test()">
<input name=ptt0201 value="测试">
<input name=ptt0202>
<input type=button value="检验数据" onclick="test()">
<input name=ptt0203>
<input name=ptt0204>
<input name=ptt0205><input type=button value="检验数据" onclick="test()">
</form><script>function test(){
for(var i=0;i<document.mxh.length;i++)
{
if((document.mxh.elements[i].type).toLowerCase()=="text")
{
if(document.mxh.elements[i].value=="")
{
alert("第 "+eval(i+1)+" 个表单元素为空啊,请输入数据!")
document.mxh.elements[i].focus()
return false;
}
}
}
alert("呵呵!过关了!:)")
}
</script>