为了账号安全,请及时绑定邮箱和手机立即绑定

js问题:如何获取checkbox选中值

js问题:如何获取checkbox选中值

眼眸繁星 2019-03-19 14:12:34
具体如下:<%!int i = 1;%> <c:forEach var="s" items="${requestScope.kaoshi.opt}"> <td align="right" valign="top" width="52"> <span class="style5"></span> <input type="checkbox" name="opt" value="<%=i%>" /> </td> <td> ${s} <br> <hr width="95%" align="left"> </td> <% i++; %> </tr> </c:forEach> 然后将其中选中的值加入: onclick="javascript:window.location='<%=request.getContextPath()%>/exam/next.do?opt=???'" 请问高手们怎么用js实习
查看完整描述

2 回答

?
三国纷争

TA贡献1804条经验 获得超7个赞

获取checkbox中所有选中值及input后面所跟的文本;
参考代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>js</title>
</head>
<script language="javascript">
function aa(){
var r=document.getElementsByName("r");
for(var i=0;i<r.length;i++){
if(r[i].checked){
alert(r[i].value+","+r[i].nextSibling.nodeValue);
}
}
}
</script>
<body>
<form name="form1" method="post" action="">
<input type="checkbox" name="r" value="1">a<br>
<input type="checkbox" name="r" value="2">b<br>
<input type="checkbox" name="r" value="3">c<br>
<input type="checkbox" name="r" value="4">d<br>
<input type="checkbox" name="r" value="5">e<br>
<input type="checkbox" name="r" value="6">f<br>
<input type="checkbox" name="r" value="7">g<br>
<input type="checkbox" name="r" value="8">h<br>
<input type="checkbox" name="r" value="9">i<br>
<input type="checkbox" name="r" value="10">j<br>
<br>
<input type="button" onclick="aa()" value="button">
</form>
</body>
</html>


查看完整回答
反对 回复 2019-03-25
  • 2 回答
  • 0 关注
  • 785 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信