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[i].value == rValue){

                        rObj[i].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>

你可能感兴趣的:(JavaScript)