简体   繁体   English

使整个行可点击

[英]Making the whole row clickable

I was trying to make a whole row of my tables on jsp page clickable for it i wrote following code in jsp page : 我试图让我在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>

And included 并包括

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="js/clickablerow.js"></script> 

at top of the page and in clickablerow.js i wrote : 在页面顶部和在clickablerow.js中,我写道:

jQuery(document).ready(function($) {
  $(".clickableRow").click(function() {
        window.document.location = $(this).attr("href");
  });
});

Am i doing something wrong?As this is not working. 我做错什么了吗?

first of all, you can reduce your jQuery ready call to: 首先,您可以将jQuery ready调用减少为:

$(function() {
}

its the exact same. 完全一样。

now, i think you would want to delegate your click handler, meaning you attach it to the document instead, so the document will search for the clickable row and handle its click events: 现在,我认为您想委托单击处理程序,这意味着您将其附加到文档上,因此文档将搜索可单击的行并处理其单击事件:

$(function() {
  $(document).on("click",".clickableRow",function() {
        window.document.location = $(this).attr("href");
  });
});

href is a wrong attribute for tr hreftr的错误属性

You can use the concept of data 您可以使用data的概念

Example: 例:

Prefix href with data 带有数据的前缀href

<tr class="clickableRow" data-href="

Write JQuery as below 编写JQuery如下

$(".clickableRow").click(function() {
        window.document.location = $(this).data("href");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM