我试图在jsp页面上创建一整行我的表格,因为我在jsp页面中编写了以下代码:
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.beans.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="js/clickablerow.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MY DATA</title>
</head>
<body>
<%!Connection con; %>
<%!PreparedStatement s; %>
<%!ResultSet rs; %>
<% String name=request.getParameter("q");
//out.println(name);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:SharedCryptography", "fyp", "fyp");
String groupidd = request.getSession().getAttribute("groupid").toString();
//out.println(groupidd);
/*String sql="select * from tbIndividual where I_NAME like ? "
+ "and I_ID in "
+ "(select I_ID from TBWAITINDIVIDUALS "
+ "where GROUP_ID <> '"+groupidd+"')";
*/
String sql="select * from tbIndividual where I_NAME like ?";
s = con.prepareStatement(sql);
s.setString(1, name + "%");
rs=s.executeQuery();
}
catch(Exception e){
e.printStackTrace();
}
%>
<div id="dtl_table"><table border='3' cellpadding='5' cellspacing='2' width="400px">
<tr bgcolor="66FF00">
<th>ID</th>
<th>NAME</th>
<th>FIRSTNAME</th>
<th>LASTNAME</th>
</tr>
<% while(rs.next())
{ %>
<%String storid=rs.getString(1);%>
<tr class="clickableRow" href="individualdetailstoadd.jsp?personid=<%=storid%>">
<td><%=storid%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
</tr>
<tr/>
<% } %>
</tr>
</table></div>
</body>
</html>
包括
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="js/clickablerow.js"></script>
在页面顶部和clickablerow.js我写道:
jQuery(document).ready(function($) {
$(".clickableRow").click(function() {
window.document.location = $(this).attr("href");
});
});
我做错了什么?因为这不起作用。
答案 0 :(得分:1)
首先,您可以将jQuery ready调用减少到:
$(function() {
}
完全相同。
现在,我认为您希望委托您的点击处理程序,这意味着您将其附加到文档,因此文档将搜索可点击的行并处理其点击事件:
$(function() {
$(document).on("click",".clickableRow",function() {
window.document.location = $(this).attr("href");
});
});
答案 1 :(得分:0)
href
是tr
您可以使用data
带数据的前缀href
<tr class="clickableRow" data-href="
按如下所示编写JQuery
$(".clickableRow").click(function() {
window.document.location = $(this).data("href");
});