[英]Making the whole row clickable
我試圖讓我在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");
});
});
我做錯什么了嗎?
首先,您可以將jQuery ready調用減少為:
$(function() {
}
完全一樣。
現在,我認為您想委托單擊處理程序,這意味着您將其附加到文檔上,因此文檔將搜索可單擊的行並處理其單擊事件:
$(function() {
$(document).on("click",".clickableRow",function() {
window.document.location = $(this).attr("href");
});
});
href
是tr
的錯誤屬性
您可以使用data
的概念
帶有數據的前綴href
<tr class="clickableRow" data-href="
編寫JQuery如下
$(".clickableRow").click(function() {
window.document.location = $(this).data("href");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.