0

我正在尝试读取 VBS 中单选按钮的值,但出现以下错误:

类型不匹配:“阶段”

在将单选按钮放入表单以根据第一个单选按钮启用/禁用复选框后,我收到此错误。

非常感谢任何帮助!

我的代码(不是整个代码,只是有缺陷的部分。Sub RunScript 由一个按钮运行):

<head>
</head>

<SCRIPT LANGUAGE="VBScript">

Sub RunScript

Dim currentphase

If phase(0).Checked Then
currentphase = phase(0).Value
End If

If phase(1).Checked Then
currentphase = phase(1).Value
End If


If currentphase = "" Then
MsgBox "Please select the phase.",48,"Error"
Exit Sub
End If

End Sub


</SCRIPT>

<body>
<form name="phaseform" action="" >
<input type="radio" name="phase" value="1" id="phase" onclick="checkbox(0)"/><label for="phase1">Phase 1</label>
<input disabled id=inorout type="checkbox" name="InorOUT" value="IN">LEGAL HOLD (<a href=javascript:RunLogFile()>?</a>) <br>
input type="radio" name="phase" value="2" id="phase" onclick="checkbox(1)" /><label for="phase2">Phase 2 (after 17 days)</label>
</form>

<script type="text/javascript">

function checkbox(val)
{
    if(val)
document.phaseform.InorOUT.setAttribute("disabled",val)
else
document.phaseform.InorOUT.removeAttribute("disabled",val)
}
</script>

</BODY>
4

3 回答 3

1

试试这个,它对我有用。

Sub RunScript
    Dim currentphase
    If phaseform.phase(0).Checked Then
        currentphase = phaseform.phase(0).Value
    End If
    If phaseform.phase(1).Checked Then
        currentphase = phaseform.phase(1).Value
    End If
    If currentphase = "" Then
        MsgBox "Please select the phase.",48,"Error"
        Exit Sub
    End If
End Sub
于 2013-05-11T19:23:09.933 回答
1

通过将 phase(0).Checked 替换为 document.phaseform.phase(0).Checked 解决

另一种方式: http ://us.generation-nt.com/answer/how-can-vbscript-retrieve-value-selected-html-radio-butto-help-151913911.html

Dim i

for i = 0 to document.phaseform.phase.length - 1
if document.phaseform.phase(i).checked then
currentphase = document.phaseform.phase(i).value
end if

next
于 2013-05-12T09:25:55.047 回答
0

您应该首先清理 HTML 部分(格式不正确的标签等):请参阅以下更正的部分

<form name="phaseform" action="">
    <input type="radio" name="phase" value="1" id="phase" onclick="checkbox(0)" />
    <label for="phase1">Phase 1</label>
    <input type="checkbox" disabled id="InorOUT" name="InorOUT" value="IN" />LEGAL HOLD (<a href=javascript:RunLogFile()>?</a>)
    <br>
    <input type="radio" name="phase" value="2" id="phase" onclick="checkbox(1)" />
    <label for="phase2">Phase 2 (after 17 days)</label>
</form>

其次,我建议在一页中使用 javascript 而不是组合 vbscript/javascript。

于 2013-05-11T12:17:38.947 回答