我有一个关于在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>
答案 0 :(得分:0)
您
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))