JSP怎么将多个复选框的value值,传到另一个页面?
来源:百度知道 编辑:UC知道 时间:2024/06/17 08:00:43
function check(){
var allCheck=document.getElementById("checkbox2");
var allChecBoxs2=document.getElementsByName("checkbox2");
for(var i=0;i<allChecBoxs2.length;i++){
if(allChecBoxs2[i].checked==true){
window.location.href("backgroud/do_DeleteInboxByState.jsp?RID=<%=request.getParameter("checkbox2")%>");
}
}
}
这是Script的一个方法. 我用<input name="Submit" type="button" class="de" value="" onclick="check()">调用它,然后另一个页面:
<%
request.setCharacterEncoding("GBK"); //支持中文编码
String s[] = request.getParameterValues("RID");
ReceiveDao redao=new ReceiveDao();
for(int i=0;i<s.length;i++){
out.print(s[i]);
}
%>
为什么out.print(s[i])输入的永远是nul
使用form表单提交RID复选框的值到backgroud/do_DeleteInboxByState.jsp页面,才可以使用String s[] = request.getParameterValues("RID"),获取数组形式的RID值。
或者使用形如:
window.location.href = "backgroud/do_DeleteInboxByState.jsp?RID=123&RID=123&RID=123";
这种格式的URL传值也可以(但是不推荐)。
function check(){
var allCheck=document.getElementById("checkbox2");
var allChecBoxs2=document.getElementsByName("checkbox2");
var url = "backgroud/do_DeleteInboxByState.jsp?";
for(var i=0;i<allChecBoxs2.length;i++){
if(allChecBoxs2[i].checked==true){
url = url + "RID="+allChecBoxs2.value + "&";
}
}
window.location.href( url );
}
【我没有做测试,但理论上是可以的。】
复选框的值<input type="checkbox" name="checkbox2" value="<%=123 %>"> 都固定的设为123了不行吗?
【复选框的 value 值不同,才有意义!】