动态收音机 VBA

Dynamic radio VBA

在此内部网站上,它允许我输入数据,并且根据数据启用单选框。我如何知道单选框何时启用。

已启用

input id="Answer1" name="Answer" type="radio" value="C"

已禁用

input id="Answer1" name="Answer" disabled="disabled" type="radio" value="C"

禁用时,getAttribute 将 return "disabled" 但启用时,它将 return 运行 时间错误

Invalid use of Null (Error 94)

如果我使用

msgbox ie.document.all("Answer1").getAttribute("disabled")

我尝试了以下 if 语句,none 将在启用时捕获它

ie.document.all("Answer1").getAttribute("disabled")  = ""
ie.document.all("Answer1").getAttribute("disabled")  = Null
ie.document.all("Answer1").getAttribute("disabled")  <> "disabled"
ie.document.all("Answer1").getAttribute("disabled")  = "disabled"  

参考:HTML disabled Attribute

Disabled 是一个布尔属性。这意味着不应设置该值(例如禁用="disabled")。如果存在 disabled,则该选项被禁用。

<option value="volvo" disabled>Volvo</option>

您应该可以使用 msgbox ie.document.all("Answer1").disabled。如果这不起作用,则捕获错误

Function isDisabled(ele As Object) As Boolean
    On Error Resume Next
       isDisabled = ele.getAttribute("disabled")
    On Error GoTo 0
End Function

我也发现这在 if 语句中也有效

if isnull(ie.document.all("Answer1").disabled) then msgbox "Radio box disabled" else msgbox "Radio box enabled" end if