标签:pre list click orm form rip doc nts value
js输出选中的值:
原生js输出:
<form action="" method="get" id="list"> 您最喜欢水果?<br /><br /> <label><input name="Fruit" type="radio" value="1"/>苹果 </label> <label><input name="Fruit" type="radio" value="2" />桃子 </label> <label><input name="Fruit" type="radio" value="3" />香蕉 </label> <label><input name="Fruit" type="radio" value="4" />梨 </label> <label><input name="Fruit" type="radio" value="5" />其它 </label> <span onclick="sum(‘Fruit‘)">SUM</span> </form>
<script> function sum(t_name){ var obj=document.getElementsByName(t_name); //得到名字为t_name的数组 for(var i=0;i<=obj.length;i++){ //遍历数组的checked值 if(obj[i].checked){ //如果选中了,输出i console.log(i); } } } </script>
jq输出:
<form action="" method="get" id="list"> 您最喜欢水果?<br /><br /> <label><input name="Fruit" type="radio" value="1"/>苹果 </label> <label><input name="Fruit" type="radio" value="2" />桃子 </label> <label><input name="Fruit" type="radio" value="3" />香蕉 </label> <label><input name="Fruit" type="radio" value="4" />梨 </label> <label><input name="Fruit" type="radio" value="5" />其它 </label> <span onclick="sum(‘radio‘)">SUM</span> </form>
<script src="js/jquery.min.js"></script> <script> function sum(radio){ var check_val=$("input[type=‘"+radio+"‘]:checked").val(); //找到选中那个数值 console.log(check_val); } </script>
标签:pre list click orm form rip doc nts value
原文地址:http://www.cnblogs.com/EllenChen/p/6666940.html