请教一个JavaScript的问题10分

starpan 2003-09-29 03:02:05
各位高手,小弟现在遇到一个问题如下:

<select name="<%=layer1(i)%>" size="1" onChange="redirect('<%=layer2(i)%>',this.options.selectedIndex)" style="WIDTH: 120px">
<option selected value="">请选择类别</option>
<option value="QGDX">待机动画</option>
<option value="WXHK">无线贺卡</option>
<option value="YMGS">幽默故事</option>
<option value="KJDH">开机动画</option>
<option value="BJCT">背景彩图</option>
</select>

上面有一个redirect函数。这个函数的描述如下:

function redirect(n,x){
var temp=document.isc.n
//alert(temp);
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)
}
我现在想要达到的目的是要把如何把n这个从那边带过来的变量用到document.isc中。(其中isc是form的name,n是变量想要表示的是Select的name.因为Select的name 是在变的。)

我遇到问题:我不知道该如何表示document.isc.n。我如果写成document.isc.+n+的话系统告诉我说是“缺少对象”请教各位高手!!
...全文
27 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
starpan 2003-09-29
  • 打赏
  • 举报
回复
这样可以的了,好的谢谢你,我现在要结贴了,希望你以后还可以帮到我。因为我的分比较少。所以只能先给你10分了。我一定会努力争取更多的分的。谢谢!
homeyang 2003-09-29
  • 打赏
  • 举报
回复
如果不行的话你就把n传出去,然后再用eval就行啦
homeyang 2003-09-29
  • 打赏
  • 举报
回复
不好意思,忘啦,呵呵,不知道这样行不行,我没试过,如果不行的话你就令想办法吧
var temp1
function redirect(n,x){
var temp = eval("document.isc." + n)
temp1=temp
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)
}

var secondGroups=temp1.options.length

starpan 2003-09-29
  • 打赏
  • 举报
回复
把var temp = eval("document.isc." + n)放在外面的话好象不行吧,我们这个变量n的值是通过redirect函数带过来的呀
homeyang 2003-09-29
  • 打赏
  • 举报
回复
放在里面肯定传不出来啦,放在外面就行啦
homeyang 2003-09-29
  • 打赏
  • 举报
回复
var temp = eval("document.isc." + n)

function redirect(n,x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)
}
这样行不行,看一下

starpan 2003-09-29
  • 打赏
  • 举报
回复
不是,我现在的意思是这样的
function redirect(n,x){
var temp = eval("document.isc." + n)
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)
}

我们不是在redirect函数中定义了temp这个变量了吗,我现在想把temp这个变量拿出到函数外面来用,请问我该如何写脚本。
就是我想在函数的外面写var secondGroups=temp.options.length这样写好象不对的,说到底就是参数传递的问题。
homeyang 2003-09-29
  • 打赏
  • 举报
回复
如果你是说付值的话用
var str="a";
eval("document.isc." + n).value=str;
starpan 2003-09-29
  • 打赏
  • 举报
回复
不过我还想问一下你,在javascript中怎么把函数中的变量的值拿出来呢?
starpan 2003-09-29
  • 打赏
  • 举报
回复
homeyang():
你好!
用eval("document.isc." + n)就行了,我现在结贴,给你加分。谢谢你!
homeyang 2003-09-29
  • 打赏
  • 举报
回复
还有语句后面要加;因为这是javascript
homeyang 2003-09-29
  • 打赏
  • 举报
回复
function redirect(n,x){
var temp="document.isc." + n
//alert(temp);
for (m=eval(temp).options.length-1;m>0;m--)
eval(temp).options[m]=null
for (i=0;i<group[x].length;i++){
eval(temp).options[i]=new Option(group[x][i].text,group[x][i].value)
}
eval(temp).options[0].selected=true
redirect1(0)
}
homeyang 2003-09-29
  • 打赏
  • 举报
回复
function redirect(n,x){
var temp=document.isc.n
//alert(temp);
for (m=eval(temp).options.length-1;m>0;m--)
eval(temp).options[m]=null
for (i=0;i<group[x].length;i++){
eval(temp).options[i]=new Option(group[x][i].text,group[x][i].value)
}
eval(temp).options[0].selected=true
redirect1(0)
}
看一下这样行不行
starpan 2003-09-29
  • 打赏
  • 举报
回复
homeyang():
你好!你能不能写的详细一点呢?
homeyang 2003-09-29
  • 打赏
  • 举报
回复
要加eval才行
如:eval("document.isc." + n).value=9

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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