[英]why my table doesn't respond when click a row
我創建了一個從數據庫中獲取值並將其顯示在表中的 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>
錯誤是我沒有定義。
您必須在showBgc
function call
打印i
值。 將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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.