1 回答

TA贡献1835条经验 获得超7个赞
主要是由于form1对象的r2、r3为radio,对于它的引用为一个数组,判断它是否选中(checked),而不能直接通过取得值的方式,例如:r2(0).value表示取得背景色为红色的值,其它类似
修改代码如下:
<body >
<form method="post" name="form1">
<p>设置背景色:<input type="radio" value="blue" checked name="r2" >蓝色
<input type="radio" value="red" name="r2" > 红色
<input type="radio" value="white" name="r2" > 白色
<input type="radio" value="black" name="r2">黑色
<input type="button" name="b3" onclick="setbkcolor(1)" value="设置" ></p>
<p>设置前景色: <input type="radio" value="blue" checked name="r3">蓝色
<input type="radio" value="red" name="r3" > 红色
<input type="radio" value="white" name="r3" > 白色
<input type="radio" value="black" name="r3" >黑色
<input type="button" name="b4" onclick="setbkcolor(2)" value="设置" ></p>
</form>
<script language="vbscript" type="text/vbscript" >
<!--
sub setbkcolor (objnum)
dim bkcolor
if objnum=1 then
Dim rv2
rv2 = getV(document.form1.r2)
document.bgcolor=rv2
elseif objNum=2 then
rv2 = getV(document.form1.r3)
document.fgcolor=rv2
end if
end sub
Function getV(xv)
Dim s, t
s = 0
t = xv.length
Do While (s < t)
If xv(s).checked Then
getV = xv(s).value
Exit Function
End If
s = s + 1
Loop
End Function
//-->
</script>
</body>
</html>
添加回答
举报