只有当表的特定列必须使用javascript显示DB中的某些值时,表的行才可见

只有当表的特定列必须使用javascript显示DB中的某些值时,表的行才可见,javascript,html,jakarta-ee,Javascript,Html,Jakarta Ee,我有一个数据库。现在我想在表中显示它的值。因此,只有当特定列必须显示数据库中的某些值时,表的行才可见。我的数据库如下所示: +--------+------+------------+---------+------+---------+---------+--------+---------+---------+--------+---------+---------+--------+ | c_name | c_id | cs_date | t_marks | nos | s_nam

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

+--------+------+------------+---------+------+---------+---------+--------+---------+---------+--------+---------+---------+--------+
| 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(let i=1;i<=3;i++){
        let 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>

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

这似乎是一个无效的连接。sroll+1。 你的循环中没有使用i计数器。 应该是这样的

        var rownum=document.getElementById("classrow"+i);
        if(document.getElementById("sroll"+i)==""){rownum.style.display='block';}
        else{rownum.style.display='none';}

我已经编辑了我的代码。那是个打字错误。对不起,我犯了这个错误。但它仍然不起作用。