如何传递复选框的值 大家好,我在A页面放了几个复选框,然后想把选择的情况传递给B页面。在A页面中,我写了action="B.jsp"请问然后在B页面怎么写来接收A页面复选框传来的值? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 能用request.getParameter(“复选框ID”)吗? 可以给LZ一个参考:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>复选框</title><script type="text/javascript" language="javascript"> <!-- function rfocus(f){ f.form.tt.value= f.value+"接收焦点"; } function reg(news){ var letter=""; var flag=0; for(var i=0;i<news.length;i++){ if(news[i].checked==true){ flag=1; letter+=news[i].value+"\n"; } } if(flag==1){ document.write("<body bgcolor='burlywood'><pre>以下是您 订阅的信息<br>"); document.write(letter+"</pre></body>"); }else{ alert("您尚未选择。"); return; } } --></script></head><body><pre> <h2>欢迎定阅时事通迅</h2> 请选择您要定阅的: <form> <input type="checkbox" name="cc" value="C" onfocus="rfocus(this)" />C <input type="checkbox" name="cc" value="C++" onfocus="rfocus(this)" />C++ <input type="checkbox" name="cc" value="C#" onfocus="rfocus(this)" />C# <input type="checkbox" name="cc" value="JAVA" onfocus="rfocus(this)" />JAVA <input type="checkbox" name="cc" value="VB" onfocus="rfocus(this)" />VB <input type="checkbox" name="cc" value="PHP" onfocus="rfocus(this)" />PHP <input type="text" size="30" name="tt" /> <br /> <input type="button" value="REG" onclick="reg(this.form.cc)" /></form></pre></body></html> String[] id = request.getParameterValues(“复选框ID”); 那个能用request.getParameterValues(“复选框ID”); 那里面能不能放 id 没试过 request.getParameterValues记得复选框他的值是一个数组~~~~~~~~所以你接收参数的时候也必须让一个数组来接受他 var obj = document.forms[1].obj;for(int i=0;i<obj.length;i++){ if(obj[i].checked){ var result = obj[i].value; }} 用request.getParameterValues("复选框Name"); +1 String []ch=request.getParameterValues("name"); ch就是接到的复选框的值的数组了 用requeset.getparameter(复选框name) getParameterValues("name");传name属性,而不是id。而且获得的是一个数组,即被选中的复选框对应的值 request.getParameterValues("复选框name");取出来是一个字符串数组注意提交表单时要用post方式 String[] id = request.getParameterValues(“复选框ID”);id 数据里存放的就是 复选框的值 如何在JSP上控制Servlet中的定时器~ The value [TestAction] for attribute [action] in tag [form] is not valid. 不知道有无谁做过权限管理的OA项目无? 一个很有深度的问题,关于http请求发送 structs中logic:equal标签 有关页面转向问题(急) FileUploadInterceptor 被执行多次 用servlet跳转时报的异常 Java处理数据库统计查询并发操作问题 关于浏览器涮新的奇怪问题 JSTL标签使用中,checkbox怎么判断是否选中 struts2通配符问题
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>复选框</title>
<script type="text/javascript" language="javascript">
<!--
function rfocus(f){
f.form.tt.value= f.value+"接收焦点";
}
function reg(news){
var letter="";
var flag=0;
for(var i=0;i<news.length;i++){
if(news[i].checked==true){
flag=1;
letter+=news[i].value+"\n";
}
}
if(flag==1){
document.write("<body bgcolor='burlywood'><pre>以下是您 订阅的信息<br>");
document.write(letter+"</pre></body>");
}else{
alert("您尚未选择。");
return;
}
}
-->
</script>
</head>
<body>
<pre>
<h2>欢迎定阅时事通迅</h2>
请选择您要定阅的:
<form>
<input type="checkbox" name="cc" value="C" onfocus="rfocus(this)" />C
<input type="checkbox" name="cc" value="C++" onfocus="rfocus(this)" />C++
<input type="checkbox" name="cc" value="C#" onfocus="rfocus(this)" />C#
<input type="checkbox" name="cc" value="JAVA" onfocus="rfocus(this)" />JAVA
<input type="checkbox" name="cc" value="VB" onfocus="rfocus(this)" />VB
<input type="checkbox" name="cc" value="PHP" onfocus="rfocus(this)" />PHP
<input type="text" size="30" name="tt" />
<br />
<input type="button" value="REG" onclick="reg(this.form.cc)" />
</form>
</pre>
</body>
</html>
那里面能不能放 id
没试过
for(int i=0;i<obj.length;i++){
if(obj[i].checked){
var result = obj[i].value;
}
}
+1 String []ch=request.getParameterValues("name"); ch就是接到的复选框的值的数组了
传name属性,而不是id。而且获得的是一个数组,即被选中的复选框对应的值
id 数据里存放的就是 复选框的值