我正在开展一个学校项目,该项目应该让学生能够搜索机构和有关它们的额外信息。
搜索后结果显示如下:无法显示图像,必须获得 10 的代表,我稍后再做。
这行得通,我使用这个 onLoad 函数:
function onLoad() {
for (i = 0; i < document.getElementsByTagName("tr").length; i++) {
if(document.getElementsByTagName("tr")[i].id.length != 0) {
document.getElementsByTagName("tr")[i].style.visibility = "collapse";
}
}
}
但是当我使用 IE7 时,我首先只获得了一些机构(通常是 19 个)
然后我按下具有此功能的加号之一:
function uitvouwen(trId,imgId) {
var url = document.getElementById(imgId).src;
if (url.indexOf("Images/plus.gif") != -1) {
for (i = 0; i < document.getElementsByTagName("tr").length; i++) {
if(document.getElementsByTagName("tr")[i].id == trId) {
document.getElementsByTagName("tr")[i].style.visibility = "visible";
}
}
url = "Images/minus.gif";
} else if(url.indexOf("Images/plusbottom.gif") != -1) {
for (i = 0; i < document.getElementsByTagName("tr").length; i++) {
if(document.getElementsByTagName("tr")[i].id == trId) {
document.getElementsByTagName("tr")[i].style.visibility = "visible";
}
}
url = "Images/minusbottom.gif";
} else if (url.indexOf("Images/minus.gif") != -1) {
for (i = 0; i < document.getElementsByTagName("tr").length; i++) {
if(document.getElementsByTagName("tr")[i].id == trId) {
document.getElementsByTagName("tr")[i].style.visibility = "collapse";
}
}
url = "Images/plus.gif";
} else if(url.indexOf("Images/minusbottom.gif") != -1) {
for (i = 0; i < document.getElementsByTagName("tr").length; i++) {
if(document.getElementsByTagName("tr")[i].id == trId) {
document.getElementsByTagName("tr")[i].style.visibility = "collapse";
}
}
url = "Images/plusbottom.gif";
}
document.getElementById(imgId).src = url;
}
奇怪的是,所有 19 个结果现在都显示出来了
所以我的问题是:
IE7 是否会停止我的 onLoad 代码(可能是因为它无法处理)还是我必须在我的程序中查找错误?
在其他浏览器上这个程序完美运行..
这是代码实际的 HTML、JSTL 和 JavaScript 代码(我知道它很乱,但它是 JSTL 的练习,所以我需要使用它):
<c:forEach var="instituut" items="${ requestScope.instituten}">
<table id="LijstResultaten<%= i %>" summary="LijstResultaten<%= i %>">
<%
i++;
if (instituten.size() != i) {
%>
<c:set var="urlLijn" scope="session" value="Images/line.gif"/>
<c:set var="urlMin" scope="session" value="Images/minus.gif"/>
<c:set var="urlPlus" scope="session" value="Images/plus.gif"/>
<c:set var="urlLijnLong" scope="session" value="Images/linelong.gif"/>
<% } else {
%>
<c:set var="urlLijn" scope="session" value="Images/empty.gif"/>
<c:set var="urlMin" scope="session" value="Images/minusbottom.gif"/>
<c:set var="urlPlus" scope="session" value="Images/plusbottom.gif"/>
<c:set var="urlLijnLong" scope="session" value="Images/empty.gif"/>
<% }
%>
<tr>
<td><img alt="" id="instituut<%= i %>" name="instituut<%= i %>" src="${ urlPlus}" onclick="uitvouwen('MeerInfoInstituut<%= i %>','instituut<%= i %>')" onmouseover="cursorVeranderen()" style="cursor: pointer;"/></td>
<td colspan="4">${instituut.name}</td>
</tr>
<tr id="MeerInfoInstituut<%= i %>">
<td><img alt="" name="lijn" src="${ urlLijn}" onclick="init();"/></td>
<td><img alt="" name="join" src="Images/join.gif"/></td>
<td colspan="2">Land:</td>
<td><%= landen.get(i - 1).getName() %></td>
</tr>
<tr id="MeerInfoInstituut<%= i %>">
<td><img alt="" name="lijn" src="${ urlLijn}"/></td>
<td><img alt="" name="join" src="Images/join.gif"/></td>
<td colspan="2">Stad:</td>
<td>${ instituut.city }</td>
</tr>
<tr id="MeerInfoInstituut<%= i %>">
<td><img alt="" name="lijn" src="${ urlLijn}"/></td>
<td><img alt="" name="join" src="Images/join.gif"/></td>
<td colspan="2">Postcode:</td>
<td>${ instituut.zipcode }</td>
</tr>
<tr id="MeerInfoInstituut<%= i %>">
<td><img alt="" name="lijn" src="${ urlLijn }"/></td>
<td><img alt="" name="join" src="Images/join.gif"/></td>
<td colspan="2">Straat:</td>
<td>${instituut.street}</td>
</tr>
<tr id="MeerInfoInstituut<%= i %>">
<td><img alt="" name="lijn" src="${ urlLijn }"/></td>
<td><img alt="" name="join" src="Images/join.gif"/></td>
<td colspan="2">Website:</td>
<td>
<c:choose>
<c:when test="${ instituut.website == 'Onbekend' }">
${ instituut.website }
</c:when>
<c:otherwise>
<a href="http://${ instituut.website }" >${ instituut.website }</a>
</c:otherwise>
</c:choose>
</td>
</tr>
<%
ArrayList<ArrayList<Outgoing_student>> studentlijst = (ArrayList<ArrayList<Outgoing_student>>) request.getAttribute("studentlijst");
ArrayList<ArrayList<Outgoing_teacher>> docentlijst = (ArrayList<ArrayList<Outgoing_teacher>>) request.getAttribute("docentlijst");
int aantalStudenten = studentlijst.get(i - 1).size();
int aantalDocenten = docentlijst.get(i - 1).size();
String resultaatStudentnamen = "";
String resultaatDocentnamen = "";
int j = 0;
for (Outgoing_student studentNamen : studentlijst.get(i - 1)) {
resultaatStudentnamen += "<tr id=\"MeerInfoStudenten" + i + "\">\n";
resultaatStudentnamen += "\t\t\t\t\t\t<td><img alt=\"\" name=\"lijn\" src=\"" + (instituten.size() != i ? "Images/line.gif" : "Images/empty.gif") + "\"/></td>\n";
resultaatStudentnamen += "\t\t\t\t\t\t<td><img alt=\"\" name=\"lijn\" src=\"Images/line.gif\"/></td>\n";
resultaatStudentnamen += "\t\t\t\t\t\t<td><img alt=\"\" name=\"join\" src=\"" + (studentlijst.get(i - 1).size() != (j + 1) ? "Images/join.gif" : "Images/joinbottom.gif") + "\"/></td>\n";
resultaatStudentnamen += "\t\t\t\t\t\t<td>" + studentNamen.getFirstname() + " " + studentNamen.getLastname() + "</td>\n";
resultaatStudentnamen += "\t\t\t\t\t</tr>\n";
j++;
}
j = 0;
for (Outgoing_teacher docentNamen : docentlijst.get(i - 1)) {
resultaatDocentnamen += "<tr id=\"MeerInfoDocenten" + i + "\">\n";
resultaatDocentnamen += "\t\t\t\t\t\t<td><img alt=\"\" name=\"lijn\" src=\"" + (instituten.size() != i ? "Images/line.gif" : "Images/empty.gif") + "\"/></td>\n";
resultaatDocentnamen += "\t\t\t\t\t\t<td><img alt=\"\" name=\"lijn\" src=\"Images/empty.gif\"/></td>\n";
resultaatDocentnamen += "\t\t\t\t\t\t<td><img alt=\"\" name=\"join\" src=\"" + (docentlijst.get(i - 1).size() != (j + 1) ? "Images/join.gif" : "Images/joinbottom.gif") + "\"/></td>\n";
resultaatDocentnamen += "\t\t\t\t\t\t<td>" + docentNamen.getFirstname() + " " + docentNamen.getLastname() + "</td>\n";
resultaatDocentnamen += "\t\t\t\t\t</tr>\n";
j++;
}
%>
<tr id="MeerInfoInstituut<%= i %>">
<td><img alt="" name="lijn" src="${ urlLijnLong }"/></td>
<td><img alt="" id="studenten<%= i %>" name="MeerInfoStudenten" src="Images/plus.gif" onclick="uitvouwen('MeerInfoStudenten<%= i %>', 'studenten<%= i %>')" style="cursor: pointer;"/></td>
<td colspan="2">Reeds bezocht door <span><%=aantalStudenten%></span> student(en)</td>
<td> </td>
</tr>
<%=resultaatStudentnamen%>
<tr id="MeerInfoInstituut<%= i %>">
<td><img alt="" name="lijn" src="${ urlLijnLong }"/></td>
<td><img alt="" id="docenten<%= i %>" name="MeerInfoDocenten" src="Images/plusbottom.gif" onclick="uitvouwen('MeerInfoDocenten<%= i %>','docenten<%= i %>')" style="cursor: pointer;"/></td>
<td colspan="2">Reeds bezocht door <span><%=aantalDocenten%></span> docent(en)</td>
<td> </td>
</tr>
<%=resultaatDocentnamen%>
</table>