站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题checkbox问题,在线等

checkbox问题,在线等

摘要: checkbox问题,在线等


<%@ page contentType="text/html; charset=UTF-8" %>
<%
String[] s = request.getParameterValues("chk");
if(s != null && s.length > 0){
for(int i = 0; i < s.length; i++){
out.println(s[i]);
}
}
%>

<head>
</head>
<body bgcolor="#ffffc0">
<form method="POST" action="case_save_test.jsp" name="frm">
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="checkbox" name="chk" value="1"/>
<input type="submit" value="h" />
</form>
</body>

我想得到这10个chk的value值,如果被选中,其值为1,否则为0
例:第一个和第二个被选中,得到s[0]=1 s[1]=1 s[2...9]=0
不用js,因为我想将数组直接传到另一个bean里
现在的难题:我只得到了被选中的值,而且不知道是第几个,假如第三个选中,得到S的长度是1,s[0]=1,其他的就没了,求大家帮忙


<input type="checkbox" name="chk" value="1"/>1
<input type="checkbox" name="chk" value="2"/>2
<input type="checkbox" name="chk" value="3"/>3
<input type="checkbox" name="chk" value="4"/>4
<input type="checkbox" name="chk" value="5"/>5
<input type="checkbox" name="chk" value="6"/>6
<input type="checkbox" name="chk" value="7"/>7
<input type="checkbox" name="chk" value="8"/>8
<input type="checkbox" name="chk" value="9"/>9
<input type="checkbox" name="chk" value="10"/>10

把每个值改成不一样不就可以了


楼上的,我知道把值改成一样的,但是改了以后只显示相应选中的,没选中的还是不显示,比如9和10选中,s的length为2


learning...


本来就是这样啊,得到选中的值就可以了,我不知道你要得到没有选中的值干吗?多此一举,如果非要得到, 只有结合JS才可以!
怎么会有这样的需求,搞不懂!


楼上的,说话不要这样子,好吗?每个人都有每个人的需求,不能拿自己的眼光看别人,只要能提出来的问题,肯定是在应用中碰到的问题,这个问题不用js也可以解决的

根据你得到的值来进行判断不就可以知道选中的是那个了吗?剩下的就是没有选中的。不明白LZ的真正用意。


↑返回目录
前一篇: jsp+servlet+javaBean,jsp页面调用出错
后一篇: 怎么在tomcat里面配虚拟目录?