单选按钮组仅在第一个输出

时间:2018-04-05 12:41:23

标签: javascript html

我有三个单选按钮组,我想隐藏最后两个单选按钮组,一旦给出第一个输出,就会显示。

代码:

  <div class="row">
    <div>
        <script type="text/javascript">
            function displaytxt(e) {
                var valueRadio = e;
                if (valueRadio == 0)
                {
                    document.getElementById('dynamictxt').style.display = 'none';
                }
                else
                {
                    document.getElementById('dynamictxt').style.display = '';
                }
            }
 </script>
        <div>
            <script type="text/javascript">
                function displaytxt1(e) {
                    var valueRadio = e;
                    if (valueRadio == 2) {
                        document.getElementById("dynamictxt1").innerHTML = "Check if the termination is for past date or future date";
                    }
                    else
                    {
                        document.getElementById("dynamictxt1").innerHTML = "Go back to the request manager for confirming the user termination date";
                    }
                }
            </script>

有没有办法使用java脚本?

提前致谢。

2 个答案:

答案 0 :(得分:0)

try like this
    <div id="rates">
      <input type="radio" id="r1" name="rate" value="Fixed Rate"> Fixed Rate
      <input type="radio" id="r2" name="rate" value="Variable Rate"> Variable Rate
      <input type="radio" id="r3" name="rate" value="Multi Rate" checked="checked"> Multi Rate  
    </div>
    if (document.getElementById('r1').checked) {
      rate_value = document.getElementById('r1').value;
    }

答案 1 :(得分:0)

我希望我能理解你的问题,但根据你问题的标题,或许,这可能会有所帮助

<form name="form1" method="post" action="">
<p id="rad1"><input type="radio" name="rdbutton" value="radio" id="rdbutton_0">
      Radio 1</p>
 <p id="rad2"><input type="radio" name="rdbutton" value="radio" id="rdbutton_1">
      Radio 2</p>
<p id="rad3"><input type="radio" name="rdbutton" value="radio" id="rdbutton_2">
      Radio 3</p>
</form>

<script>
$('#rad1').on('click',function(){
    hideSelects();
});

function hideSelects() {
    $('p#rad2').hide();
    $('p#rad3').hide();
};
</script>

Demo