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

具体如下:<%!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实习

眼眸繁星
浏览 787回答 2
2回答

三国纷争

获取checkbox中所有选中值及input后面所跟的文本;参考代码如下:<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>js</title></head><script&nbsp;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>
打开App,查看更多内容
随时随地看视频慕课网APP