请问列表中的options是如何使用的?

zhdaring 2004-08-06 06:34:56
我正在学习列表的用法,但是对如何引用它当中的一行不太明白。
如下,如果将出问题的两行注释掉,可以正常运行,可这两行应该如何写才对呢?也就是说,我如何用options来引用当前选择的行呢?





<html>
<head>

<SCRIPT language="VBScript">
<!--
function chgsel()
dim thisform,sel
set thisform=document.form1
sel=thisform.select.value
sel=thisform.select.selectedindex+1
thisform.boardname.value=board(sel,1)
thisform.userlist.value=board(sel,1)
thisform.userlist.value=thisform.select.options.value
'出问题的两行
' thisform.userlist.value=thisform.select.options[sel].value
' thisform.userlist.value=thisform.select.options[sel].text

chgsel=true
end function
-->
</SCRIPT>

<SCRIPT language="VBScript">
<!--
dim board(20,5)
board(1,1)="aaaa"
board(2,1)="bbbb"
board(3,1)="cccc"
board(4,1)="dddd"
board(5,1)="eeee"
board(6,1)="ffff"
board(7,1)=""
board(1,2)="1111"
board(2,2)="2222"
board(3,2)="3333"
board(4,2)="4444"
board(5,2)="5555"
board(6,2)="6666"
-->
</SCRIPT>



</head>

<body>
<form name="form1" method="post" action="">
<p>
<select name="select" size="5" onChange="return=chgsel()">
<option value="1">aaaaaaaa</option>
<option value="2">bbb</option>
<option value="3">ccc</option>
<option value="4">ddd</option>
<option value="5">eee</option>
<option value="6">fff</option>
</select>
<label></label></p>
<p>
<label>ID</label>
<input name="boardname" type="text">
<input type="text" name="userlist">
</p>

</form>
</body>
</html>
...全文
210 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2004-08-07
  • 打赏
  • 举报
回复
<form id=f>
年<SELECT id=s1 name=s1 onchange="vbs:aaa"></SELECT>
月<SELECT id=s2 name=s2 onchange="vbs:aaa"></SELECT>
日<SELECT id=s3 name=s3></SELECT>
</form>
<SCRIPT LANGUAGE=vbscript>
'初始年
MyAdd "f.s1",1970,2050
'初始月
MyAdd "f.s2",1,12
'初始日
MyAdd "f.s3",1,31
sub MyAdd(S,x,y)'增加
set obj=eval(S)
for i=x to y
set o=document.createElement("OPTION")
o.text=i
o.value=i
obj.add o
next
end sub
sub MyRemove(S)'删除
set obj=eval(S)
for each opt in obj.options
obj.remove opt.index
next
end sub
sub aaa'自定义过程,用来改变s3日期
dim mydate,maxdate
'先清空全部,最好从28号以后清空,但是这样效率低人感觉不到,偷点懒不是罪
MyRemove "f.s3"
for i=1 to 31
mydate=f.s1.value & "-" & f.s2.value & "-" & i
if isdate(mydate) then '判断是否是有效日期
maxdate=i
else
exit for
end if
next
MyAdd "f.s3",1,maxdate
end sub
</SCRIPT>
cuixiping 2004-08-06
  • 打赏
  • 举报
回复
是不是写错了,怎么连着给thisform.userlist.value赋值了好多遍?

vbs里面是用括号来表示数组的元素和列举集合里的成员:

thisform.userlist.value=thisform.select.options(sel-1).value

注意: 是(sel-1)而不是楼上的(sel),否则你选最后一项时会出错。
因为你的sel=thisform.select.selectedindex+1 已经加了1了.
options的索引仍然是从0开始的,无论是否在vbs里。
mjpclab 2004-08-06
  • 打赏
  • 举报
回复
thisform.userlist.value=thisform.select.options(sel).value
thisform.userlist.value=thisform.select.options(sel).text

VBscript数组是用()的

28,390

社区成员

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

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