单选的radia,和多选的checkbox取值

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 5 <title></title>
 6 <script type="text/javascript">
 7 function getRadioValue(radioName) {
 8     var rs = document.getElementsByName(radioName);
 9     for (var i = 0; i < rs.length; i++) {
10         if (rs[i].checked) {
11             alert(rs[i].value);
12         }
13     }
14 }
15 function getCheckboxValue(checkName) {
16     var cs = document.getElementsByName(checkName);
17     document.getElementById("d1").innerHTML = "<br />以下checkBox被选中了:<br />";
18     for (var i = 0; i < cs.length; i++) {
19         if (cs[i].checked) {
20             document.getElementById("d1").innerHTML += cs[i].value;
21         }
22     }
23 }
24 </script>
25 </head>
26 <body>
27 <input type="radio" name="r" id="a" value="a" />
28 <label for="a"> 点击选择a </label>
29 <input type="radio" name="r" id="b" value="b" />
30 <label for="b"> 点击选择b </label>
31 <input type="button" value="radio" onclick="getRadioValue('r');" />
32 <br />
33 <br />
34 <input type="checkbox" name="c" id="c1" value="c1" />
35 <label for="c1"> 点击选择c1 </label>
36 <input type="checkbox" name="c" id="c2" value="c2" />
37 <label for="c2"> 点击选择c2 </label>
38 <input type="checkbox" name="c" id="c3" value="c3" />
39 <label for="c3"> 点击选择c3 </label>
40 <input type="button" value="checkBox" onclick="getCheckboxValue('c');" />
41 <div id="d1"></div>
42 
43 </body>
44 </html>
View Code

 

转载于:https://www.cnblogs.com/lrh-liuronghua/p/3281804.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值