js操作radio个人小总结
一下有不合适的地方或是编码效率低的地方欢迎指正。
获取radio信息:
$('detail').value = "radioValue:"+ roViewTypeValue+";radioText: "+chkObjs[i].nextSibling.data.trim()+";并设置"+chkObjs[i].nextSibling.data.trim()+"为选
1 <html> 2 <head> 3 <script type="text/javascript"> 4 function $(id){ 5 return document.getElementById(id); 6 } 7 8 String.prototype.trim = function () { 9 return this.replace(/(^\s*)|(\s*$)/g, ""); 10 }; 11 function foo() 12 { 13 var gloal = (function(){return this;}()); 14 //信号源过滤 15 var chkObjs = document.getElementsByName("roViewType"); 16 var roViewTypeValue = ""; 17 18 for(var i=0,len=chkObjs.length;i<len;i++){ 19 if(chkObjs[i].checked){ 20 roViewTypeValue = chkObjs[i].value; 21 $('detail').value = "radioValue:"+ roViewTypeValue+";radioText: "+chkObjs[i].nextSibling.data.trim()+";并设置"+chkObjs[i].nextSibling.data.trim()+"为选中的radio"; 22 break; 23 } 24 } 25 } 26 </script> 27 </head> 28 <body> 29 <div height="100px"> 30 <fieldset> 31 <legend><strong>信号类型</strong></legend> 32 <input type="radio" id="roViewType0" name="roViewType" value="0" onclick="channelInitLw()" checked="true">所有信源 33 <input type="radio" id="roViewType9" name="roViewType" value="9" onclick="channelInitLw()">中波调频广播 34 <input type="radio" id="roViewType10" name="roViewType" value="10" onclick="channelInitLw()">有线模拟电视 35 <input type="radio" id="roViewType1" name="roViewType" value="1" onclick="channelInitLw()">有线数字电视 36 <input type="radio" id="roViewType8" name="roViewType" value="8" onclick="channelInitLw()">IPTV 37 <input type="radio" id="roViewType7" name="roViewType" value="7" onclick="channelInitLw()">CMMB 38 <input type="radio" id="roViewType6" name="roViewType" value="6" onclick="channelInitLw()"> DTMB 39 <input type="radio" id="roViewType2" name="roViewType" value="2" onclick="channelInitLw()">卫星数字电视 40 <input type="radio" id="roViewType11" name="roViewType" value="11" onclick="channelInitLw()">开路模拟电视 41 <br> 42 <input type="text" id="detail" name="qwe" style="width: 602px" value="没有选择" > 43 <input type="button" id="roViewType12" name="buttonname" value="获取选中的信息" onclick="foo()"> 44 </fieldset> 45 </div> 46 </body> 47 </html>