我一直在我的代码中收到此错误。错误 - 未捕获TypeError:无法设置属性'innerHTML'的未定义
Uncaught TypeError: Cannot set property 'innerHTML' of undefined
我已阅读了一些类似的错误Uncaught TypeError: Cannot set property 'innerHTML' of undefined of null
和我已经尝试了一些建议的方法,但似乎没有任何改变。
它似乎指向这条线document.getElementsByClassName("demo")[i].innerHTML = xhttp.responseText;
我不明白为什么像我之前添加循环,它工作正常。
我的代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/DVerto.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_DVerto_STRING
Recordset1_cmd.CommandText = "SELECT Part_Number FROM dbo.Stock_Header WHERE Part_Number like '84%'"
Recordset1_cmd.Prepared = true
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 10
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body onLoad="loadDoc()">
<table width="50%" border="0" cellspacing="2" cellpadding="2">
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr>
<td class="prodref"><%=(Recordset1.Fields.Item("Part_Number").Value)%></td>
<td class="demo"> </td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table>
<script>
var a = document.getElementsByClassName("prodref").length;
var i = 0;
for (i; i < a; i++) {
loadDoc();
}
function loadDoc() {
var a = document.getElementsByClassName("prodref");
a[i] = document.getElementsByClassName("prodref").innerHTML;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementsByClassName("demo")[i].innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "data.asp?prodref="+a[i].innerHTML, true);
xhttp.send();
}
</script>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
你有没有叫“demo”的类? –
@LJa是的,我的一个表格单元格有一类'demo' - '