javascript - 为什么单击一行时我的表格没有响应
问题描述
我创建了一个从数据库中获取值并将其显示在表中的 JSP。现在我想为表格创建一个点击功能。单击将显示一些值的行。我为此使用了一个 js 代码,但是当我单击该行时,什么也没发生。任何人都可以帮忙吗?谢谢。
<%@ 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>
我在 IE 中调试它。html就像
<tr>
<td onclick="showBgc(i)">DE01</td>
<td onclick="showBgc(i)">Country Template DE</td>
</tr>
我没有定义错误。
解决方案
您必须i
在showBgc
function call
. 更改showBgc(i)
为showBgc(<%=i%>)
,否则该函数将i
作为字符串值。
例子:
%>
<tr>
<td onclick="showBgc(<%=i%>)"><%=news.getValue("Code") %></td>
<td onclick="showBgc(<%=i%>)"><%=news.getValue("Name") %></td>
</tr>
<%
显示code
和Name
。
<tr>
<td onclick="showBgc('<%=news.getValue("Code") %>')"><%=news.getValue("Code") %></td>
<td onclick="showBgc('<%=news.getValue("Name") %>')"><%=news.getValue("Name") %></td>
</tr>
推荐阅读
- scala - 用于对桶中的整数进行分组的 Spark 代码
- git - 执行 git svn clone 命令时出现“命令返回错误:127”
- stored-procedures - DBMS 是否以存储过程的形式在 DBMS 服务器上保存来自准备好的语句的编译查询?
- java - 自动分区/批处理大型 Spring Data JPA 子句
- pandas - 使用 svd 求解欠定的 scipy.sparse 矩阵
- c++ - 如何填充包含指针数组的结构数组
- ruby-on-rails - 参数数量错误(给定 1,预期为 0)
- c# - 为什么go1没有价值
- javascript - 如何使复选框禁用?
- c# - Gzip 压缩中间件在 asp.net core 2.0 中不起作用