【问题标题】:Check dynamic checkboxes vbscript检查动态复选框 vbscript
【发布时间】:2014-10-27 19:02:58
【问题描述】:

我有一个关于在 VBscript 中使用复选框的问题。我有一个大的excel文件,里面有几列数据。我使用 vbscript 构建我的 HTML,并从 excel 文件中读取复选框名称,然后将其保存在一个数组中。直到那里,一切正常。 当我想检查复选框是否被选中时,我收到错误 'Object required' 'groupnames' 我当然知道我做错了什么,但我似乎无法找到解决方案。有没有人可以帮助我?

<html>
<head>
<title>Check groups</title>
<HTA:APPLICATION
  APPLICATIONNAME="Check groups"
  ID="Dynamically_check_groups"
  VERSION="1.0"/>
</head>

<SCRIPT LANGUAGE="VBScript">
Dim objExcel, objWorkbook, counter
dim groupnames(90)
counter = 0

Sub Window_OnLoad
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open ("D:\Groups.xls")
    dim strHTML, intRow
    For intRow = 2 to 90
        If objExcel.Cells(intRow,4).Value = "sport" Then
            if ObjExcel.Cells(intRow,5).Value = "vast" Then
                strHTML = strHTML & "<input type="&Chr(34)& "checkbox"&Chr(34)& "  name="&Chr(34)& objExcel.Cells(intRow,2) &Chr(34)& ">" &objExcel.Cells(intRow,1) &" <br>"
                groupnames(counter) = objExcel.Cells(intRow,2).value
                counter = counter + 1
            End if
        End if
    Next
    objExcel.Quit
    DataArea.InnerHTML = strHTML
End Sub

Sub Check_Groups
    Dim i, name
    For i = 0 to counter - 1  
        If groupnames(i).checked Then
            Msgbox groupnames(i) & "was checked."
        End if
    Next

End Sub
</SCRIPT>



<body bgcolor="white">
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td valign="top"><Div id="DataArea"></Div></td>
        </tr>
        <tr>
            <td>
        <button style="width:200;height:50" name="chkgroups" id="chkgroups" accessKey="C" onClick="vbs:Check_groups">Controleer groepen</button>
            </td>
        </tr>
    </table>
</body>
</html>

【问题讨论】:

    标签: excel checkbox vbscript hta


    【解决方案1】:

    你的

    If groupnames(i).checked Then
    

    尝试访问名称/字符串的 .checked 属性,该名称/字符串是名为 groupnames 的字符串数组中的第 i 个元素。您需要的是具有该名称的 DOM 对象/元素。所以

    Set o = document.getElementById(groupnames(i))
    If o.checked Then
    

    或者,您可以访问 .all 集合:

    Set o = document.all(groupnames(i))
    

    【讨论】:

      猜你喜欢
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 2014-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多