在javascript循环取值的问题

r_qdd 2002-12-03 02:49:04
我写了一个函数
function checkattribinput(count){
alert(count);
for (i=0;i<count;i++){
if ("document.form1.attribname"+(i+1)+".value==2"){
alert("属性名"+(i+1)+"不能为空,请输入");

return false;
}
}
return true;
}
要循环取attribname1,attribname2,attribname3........attribname(count-1)的值,但是我写的函数为什么取不出来呀!请各位高手给指点指点 不胜感激!
...全文
45 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangxj0600 2002-12-03
  • 打赏
  • 举报
回复
eval
yonghengdizhen 2002-12-03
  • 打赏
  • 举报
回复
其实你的这样设计并不科学.在server端将需要很多附加操作..
比较合理的是用相同的名字命名然后用如下的语句:
function checkattribinput(){
for (i=0;i<document.form1.all("attribname").length;i++)
{
if (document.form1.all("attribname")[i].value==2)
{
alert("属性名"+(i+1)+"不能为空,请输入");
document.form1.all("attribname")[i].focus();
return false;
}
}
return true;
}
meizz 2002-12-03
  • 打赏
  • 举报
回复
if (eval("document.form1.attribname"+(i+1)).value==2){

USE eval
3332221119 2002-12-03
  • 打赏
  • 举报
回复
function checkattribinput(count){
alert(count);
for (i=0;i<count;i++){
if (eval("document.form1.attribname"+(i+1)).value==2){
alert("属性名"+(i+1)+"不能为空,请输入");

return false;
}
}
return true;
}
yonghengdizhen 2002-12-03
  • 打赏
  • 举报
回复
function checkattribinput(count){
alert(count);
for (i=0;i<count;i++){
if (eval("document.form1.attribname"+(i+1)+".value==2")){
alert("属性名"+(i+1)+"不能为空,请输入");

return false;
}
}
return true;
}
3332221119 2002-12-03
  • 打赏
  • 举报
回复
function checkattribinput(count){
alert(count);
for (i=0;i<count;i++){
if (eval("document.form1.attribname"+(i+1).value==2){
alert("属性名"+(i+1)+"不能为空,请输入");

return false;
}
}
return true;
}

87,955

社区成员

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

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