![]() |
#2
yms1232011-03-23 13:03
![]() <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www."> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>下拉列表随机选中测试 </title> <script type="text/vbscript" language="vbscript"> '判断是否数字 Function IsNum(val) On Error Resume Next IF VarType(CInt(val))<>2 Then IsNum=False Else IsNum=True End IF End Function '生成下拉列表选项按钮事件 Function MarkSelect_Click() Dim MaxLen,i '获得文本框OptionNum输入的内容 MaxLen=document.getElementById("OptionNum").value '判断文本框输入的是否正确 IF MaxLen="" Then MsgBox "不能为空" Exit Function End IF IF Not IsNum(MaxLen) Then MsgBox "输入的非整数" Exit Function End IF IF MaxLen>1000 Then MsgBox "最大数值为1000" Exit Function End IF IF MaxLen<=0 Then MsgBox "不能小于0" Exit Function End IF '生成下拉列表选项代码 selShow.options.length=0'初始化下拉选项个数为0 '循环添加下拉列表选项 For i=0 To MaxLen Dim opt Set opt=document.createElement("option")'创建一个下拉列表选项 '给创建的下拉列表选项赋值 opt.text=i opt.value=i selShow.add opt '将创建的选项添加入下拉列表 Next End Function '随机选择事件按钮 Function Random_Click() Dim selLen,rndNum Randomize '初始化随机数 selLen=selShow.options.length '获得下拉列表的选项个数 IF selLen<=0 Then Exit Function '判断选项个数是否小于0 rndNum=Int((selLen*Rnd)+0)'在下拉列表的选项中产生一个随机数 selShow.options(rndNum).selected=True'设置某项被选中 End Function </script> </head> <body> <p>下拉列表随机选中测试 </p> <p> <input type="text" id="OptionNum"/> 输入选项个数<input id="MarkSelect" onclick="MarkSelect_Click()" type="button" value="生成选项" /></p> <p> <select id="selShow"> </select> <input type="button" id="Random" onclick="Random_Click()" value="开始"/> </p> </body> </html> [ 本帖最后由 yms123 于 2011-3-23 13:27 编辑 ] |
以下是部分代码
<input name="option1" type="radio" value="1" />
<input name="option1" type="radio" value="2" />
<input name="option1" type="radio" value="3" />
dim x
randomize
x = int(rnd()*3)+1
if document.getElementById("option1").value = x then
....(中间这段我想让符合value = x 的单选按钮被选中)
end if