Javascript 使用jquery将值从一行传递到另一个JSP
在使用jQuery时,我试图从一个引导表中获取行值,以便将它们发送到另一个JSP文档,但似乎找不到一种合适的方法来实现这一点Javascript 使用jquery将值从一行传递到另一个JSP,javascript,jquery,twitter-bootstrap,jsp,Javascript,Jquery,Twitter Bootstrap,Jsp,在使用jQuery时,我试图从一个引导表中获取行值,以便将它们发送到另一个JSP文档,但似乎找不到一种合适的方法来实现这一点 <table class="table table-hover"> <thead> <% int serial = 0; int id = 0; String name
<table class="table table-hover">
<thead>
<%
int serial = 0;
int id = 0;
String name = null;
double ammount = 0;
String date = null;
User user = null;
%>
<tr>
<th><%="Serial"%></th>
<th><%="Cost ID"%></th>
<th><%="Cost Name"%></th>
<th><%="Cost Ammount"%></th>
<th><%="Cost Date"%></th>
</tr>
</thead>
<tbody>
<%
try {
int id_id = (int) session.getAttribute("id");
List<Object[]> costs = scm.viewAll(sum.getUser(id_id));
for (Object[] cost : costs) {
id = (int) cost[0];
name = (String) cost[1];
ammount = (double) cost[2];
date = (String) cost[3];
serial += 1;
%>
<tr class="clickable-row" data-href="updatesingle">
<td><%=serial%></td>
<td><%=id%></td>
<td><%=name%></td>
<td><%=ammount%></td>
<td><%=date%></td>
</tr>
<%
}
} catch (Exception e) {
response.sendRedirect("home");
}
%>
我试图做的是,例如,将costid(ID变量)值传递到下一个JSP页面,并以某种方式对其进行操作,该值应该是我单击的特定行的值。有没有办法做到这一点
p.S我是jQuery新手,所以请温和:)您可以将id保存在
数据-
属性中:
<tr class="clickable-row" data-href="updatesingle" data-id="<%=id%>">
但是,如果要在另一个页面中使用jQuery获取该ID,可以将该ID保存到sessionStorage中:
sessionStorage.setItem('clickedUserID', $(this).data("id"));
window.document.location = $(this).data("href");
在另一个页面中,您只需从sessionStorage获取并使用它:
var userID = sessionStorage.getItem('clickedUserID');
// do something with the ID
Pro提示:如果您只是将
字符串打印到JSP中,只需将其键入HTML(并保存额外的编码)
以下是我试图回答你的问题:
$(文档).ready(函数($){
$(“.clickable行”)。单击(函数(){
//您可以在此处添加新页面的URL,如下所示:
//var newLocation=“?paramName=“+paramValue”
//这只是一个如何工作的例子
var newLocation=window.document.location+“?href=“++$(this.data)(“href”);
警报(新位置);
//oher值
console.log($(this.find(“td”).eq(1.html());//1表示id列,2表示名称,3表示金额,等等。
window.document.location=新位置;
});
});代码>
电视连续剧
成本ID
成本名称
成本金额
成本日期
1.
id1
名称1
数量1
日期1
2.
id2
姓名2
数量2
日期2
3.
id3
名字3
数量3
日期3
您可以将其作为搜索参数附加到重定向urlurl?id=#
sessionStorage.setItem('clickedUserID', $(this).data("id"));
window.document.location = $(this).data("href");
var userID = sessionStorage.getItem('clickedUserID');
// do something with the ID