[英]why my table doesn't respond when click a row
I ceate a JSP which fetch value from database and displayed it in a table.我创建了一个从数据库中获取值并将其显示在表中的 JSP。 Now I want to create a click function for the table.
现在我想为表格创建一个点击功能。 Click the row it will display some value.
单击将显示一些值的行。 I use a js code for it but when I click the line nothing happened.
我为此使用了 js 代码,但是当我单击该行时什么也没发生。 Can anyone help?
任何人都可以帮忙吗? Thanks.
谢谢。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="SCOfetch.*" %>
<%@ page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>First Page</title>
<% JCOtest connection1 = new JCOtest(); %>
<%
ArrayList<CompanyRecord> list = new ArrayList<CompanyRecord>();
list = connection1.step4QueryTable();
%>
//*This is the click function*
<script language="javascript">
function showBgc(idn){
alert (idn);
}
</script>
</head>
<body>
<c:set var="greeting" value="Hello, World!"/>
<!-- <img id="image-1" alt="" src="img/snow.jpg" width="300" height="300"/> -->
//This is the result table
<table>
<%
int size=list.size();
for(int i=0;i<size;i++){
CompanyRecord news =(CompanyRecord)list.get(i);
%>
<tr>
<td onclick="showBgc(i)"><%=news.getValue("Code") %></td>
<td onclick="showBgc(i)"><%=news.getValue("Name") %></td>
</tr><%
}
%>
</table>
</body>
</html>
And I debug it in IE.我在 IE 中调试它。 the html is like
html就像
<tr>
<td onclick="showBgc(i)">DE01</td>
<td onclick="showBgc(i)">Country Template DE</td>
</tr>
and the error is i not defined.错误是我没有定义。
You have to print the i
value in the showBgc
function call
.您必须在
showBgc
function call
打印i
值。 Change showBgc(i)
to showBgc(<%=i%>)
, otherwise the function will take i
as a string value.将
showBgc(i)
更改为showBgc(<%=i%>)
,否则函数会将i
作为字符串值。
Example:例子:
%>
<tr>
<td onclick="showBgc(<%=i%>)"><%=news.getValue("Code") %></td>
<td onclick="showBgc(<%=i%>)"><%=news.getValue("Name") %></td>
</tr>
<%
To show code
and Name
.显示
code
和Name
。
<tr>
<td onclick="showBgc('<%=news.getValue("Code") %>')"><%=news.getValue("Code") %></td>
<td onclick="showBgc('<%=news.getValue("Name") %>')"><%=news.getValue("Name") %></td>
</tr>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.