表的一行仅在其特定列必须使用javascript显示数据库某些值的情况下才可见

问题描述 投票:0回答:1

我有一个数据库。现在,我想在表中显示它的价值。因此,仅当特定列必须显示数据库中的某些值时,表的行才可见。我的数据库如下所示:

+--------+------+------------+---------+------+---------+---------+--------+---------+---------+--------+---------+---------+--------+
| c_name | c_id | cs_date    | t_marks | nos  | s_name1 | s_roll1 | marks1 | s_name2 | s_roll2 | marks2 | s_name3 | s_roll3 | marks3 |
+--------+------+------------+---------+------+---------+---------+--------+---------+---------+--------+---------+---------+--------+
| 22     | 22   | 2019-11-04 | 44      | 2    | A1      | 01      | 22     | A2      | 02      | 22     |         |         |        |
+--------+------+------------+---------+------+---------+---------+--------+---------+---------+--------+---------+---------+--------+

现在这是我尝试过的以下jsp页面:

<%@page import="beans.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script>
function showRow(){
    for(var i=1;i<=3;i++){
        var rownum=document.getElementById("classrow"+i);
        if(document.getElementById("sroll"+i)==""){rownum.style.display='block';}
        else{rownum.style.display='none';}
    }
}
</script></head>
<body>
<%
    class1 classd = (class1)session.getAttribute("classd");
    if(classd != null){
%>
<table align="center"><tr>
<th>Class<br>Name</th>
<th>Class<br>Total Marks</th>
<th>Class<br>Start Date<br>(Class ID)</th>
<th>Student<br>Name</th>
<th>Student<br>Roll</th>
<th>Student<br>Marks</th></tr>
<tr id="classrow1" style='display:none'>
<td><%=classd.getCname() %></td>
<td><%=classd.getTmarks() %></td>
<td><%=classd.getCsdate() %> (<%=classd.getCid() %>)</td>
<td><%=classd.getSname1() %></td>
<td id="sroll1"><%=classd.getSroll1() %></td>
<td><%=classd.getMarks1() %></td></tr>
<tr id="classrow2" style='display:none'>
<td></td>
<td></td>
<td><%=classd.getCsdate() %> (<%=classd.getCid() %>)</td>
<td><%=classd.getSname2() %></td>
<td id="sroll2"><%=classd.getSroll2() %></td>
<td><%=classd.getMarks2() %></td></tr>
<tr id="classrow3" style='display:none'>
<td></td>
<td></td>
<td><%=classd.getCsdate() %> (<%=classd.getCid() %>)</td>
<td><%=classd.getSname3() %></td>
<td id="sroll3"><%=classd.getSroll3() %></td>
<td><%=classd.getMarks3() %></td></tr></table>
<%
}
%>
</body></html>

但是我没有得到理想的结果。请帮忙。我知道这很容易,但是我是这个学科的新手。

javascript html java-ee
1个回答
0
投票

这似乎是无效的串联。 "sroll"+1。您的循环中没有使用i计数器。应该是这样。

        var rownum=document.getElementById("classrow"+i);
        if(document.getElementById("sroll"+i)==""){rownum.style.display='block';}
        else{rownum.style.display='none';}
© www.soinside.com 2019 - 2024. All rights reserved.