heisetoufa 发表于 2013-2-7 19:50:55

js javascript 根据后台的值默认选中单选按钮,radio,单选默认值,单选扭默认

<html>    <head>      <title>初始化单选</title>      <script>            function initradio(rName,rValue){                var rObj = document.getElementsByName(rName);                for(var i = 0;i < rObj.length;i++){                  if(rObj.value == rValue){                        rObj.checked ='checked';                  }                }            }      </script>    </head>    <body>      <form action="#">            黑<input type="radio" name="tRadio" value="1">            色<input type="radio" name="tRadio" value="2">            头<input type="radio" name="tRadio" value="3">            发<input type="radio" name="tRadio" value="4">      </form>      <script>            initradio('tRadio',3);      </script>    </body></html>

黑色头发:http://heisetoufa.iteye.com
页: [1]
查看完整版本: js javascript 根据后台的值默认选中单选按钮,radio,单选默认值,单选扭默认