我一直在这个工作了几天,我还没有弄明白。我有一个HTML页面,它有两组输入,每一组都包含一个单选按钮和一些文本。我需要:vbscript禁用/启用html输入
- 所有的文字输入被禁用时,页面加载
- 单选按钮#1,以启用它的文字输入和禁用单选按钮#文本输入2
- 单选按钮#2以使它的文本输入并禁止对单选按钮#1
在这里,文本输入的一些示例代码:
<html>
<script type="text/vbscript">
<!--<![CDATA[
function enable()
if document.GetElementByID("radio1").checked then
document.GetElementByID("radio2").checked = false
document.GetElementByID("text1").disabled = false
document.GetElementByID("text2").disabled = true
elseif document.GetElementByID("radio2").checked then
document.GetElementByID("radio1").checked = false
document.GetElementByID("text1").disabled = true
document.GetElementByID("text2").disabled = false
else
document.GetElementByID("text1").disabled = true
document.GetElementByID("text2").disabled = true
end if
end function
-->]]>
</script>
<body onload="enable()">
<table border=1>
<tr>
<td>
<input type="radio" id="radio1" name="radio1" value="radio1" onclick="enable()">
<label for="radio1" >
Radio 1
</label>
</td>
<td>
<input type="text" id="text1" name="text1" value="hi">
</td>
</tr>
<tr>
<td>
<input type="radio" id="radio2" name="radio2" value="radio2" onclick="enable()">
<label for="radio2" >
Radio 2
</label>
</td>
<td>
<input type="text" id="text2" name="text2" value="bye">
</td>
</tr>
</table>
</body>
</html>
看起来我可以部分工作,但不是全部。事实上,这将最终以HTA形式出现。
编辑:
由于双方@kingdomcreation和@Teemu,我现在有单选按钮任意数量的这种工作的解决方案:
<html>
<script type="text/vbscript">
<!--<![CDATA[
function enable(num)
document.getElementById("text" & num).disabled = false
for i = 1 to 6
if document.getElementById("radio" & i).checked = false Then
document.getElementById("text" & i).disabled = true
end if
next
end function
-->]]>
</script>
<body>
<table border=1>
<tr>
<td>
<input type="radio" id="radio1" name="radio" value="radio1" onClick="enable(1)">
<label for="radio1" >
Radio 1
</label>
</td>
<td>
<input disabled type="text" id="text1" name="text1" value="hi">
</td>
</tr>
<tr>
<td>
<input type="radio" id="radio2" name="radio" value="radio2" onClick="enable(2)">
<label for="radio2" >
Radio 2
</label>
</td>
<td>
<input disabled type="text" id="text2" name="text2" value="there">
</td>
</tr>
<tr>
<td>
<input type="radio" id="radio3" name="radio" value="radio3" onClick="enable(3)">
<label for="radio3" >
Radio 3
</label>
</td>
<td>
<input disabled type="text" id="text3" name="text3" value="how">
</td>
</tr>
<tr>
<td>
<input type="radio" id="radio4" name="radio" value="radio4" onClick="enable(4)">
<label for="radio4" >
Radio 4
</label>
</td>
<td>
<input disabled type="text" id="text4" name="text4" value="are">
</td>
</tr>
<tr>
<td>
<input type="radio" id="radio5" name="radio" value="radio5" onClick="enable(5)">
<label for="radio5" >
Radio 5
</label>
</td>
<td>
<input disabled type="text" id="text5" name="text5" value="you">
</td>
</tr>
<tr>
<td>
<input type="radio" id="radio6" name="radio" value="radio6" onClick="enable(6)">
<label for="radio6" >
Radio 6
</label>
</td>
<td>
<input disabled type="text" id="text6" name="text6" value="bye">
</td>
</tr>
</table>
</body>
</html>
这个人很有希望。谢谢。我没有意识到两个按钮的'name'属性必须相同。 – meffordm 2013-03-06 14:09:03