Registerscript(HTML和Javascript)

时间:2013-03-06 13:12:53

标签: javascript html

我正在编写一个注册脚本,但我被卡住了。我有一个用户付费或免费会员资格的机会。当他们选择“支付”时,支付栏变得可见,但如果我之后选择“免费”,我会看到免费和付费栏。但我只希望看到一列不同时出现

的Javascript

            <script type="text/javascript">
            function betal(value) {
                if (value == 'show') { document.getElementById('betalversion').style.display = 'block'; }
                else { document.getElementById('betalversion').style.display = 'none'; }
            }
        </script>

        <script type="text/javascript">
            function gratis(value) {
                if (value == 'show') { document.getElementById('gratisversion').style.display = 'block'; }
                else { document.getElementById('gratisversion').style.display = 'none'; }
            }
        </script>

HTML

<div class="FormGroup">
                <h2 class="description">Vad skulle du vilja ha?</h2>
                <label class="choice">
                    <input id="gratisVersion" name="field_Payment" type="radio" value="Gratis" class="required" onclick="gratis('show');">
                    Gratis Version</label>
                <br />
                <label class="choice">
                    <input id="betalVersion" name="field_Payment" type="radio" value="Betal" class="required" onclick="betal('show');">
                    Betal Version</label>

                <br />
            </div>

            <div class="FormGroup" style="display: none" id="betalversion">
                <br />
                <h2 class="description">Fyll i dina uppgifter</h2>
                <br>
                <div class="explanation">Här är nåt</div>
                <input type="text" name="paypal_address" id="Text1" size="40">
            </div>

            <div class="FormGroup" style="display: none" id="gratisversion">
                <br />
                <h2 class="description">Fyll i dina uppgifter</h2>
                <br>
                <label for="name">Användarnamn</label><input type="text" name="name" id="name"/>
        <br />
                <label for="pass">Lösenord</label><input type="password" name="pass" id="pass" onkeyup="passwordStrength(this.value)" />
                <br />

                <p>

2 个答案:

答案 0 :(得分:1)

   <script type="text/javascript">

    function betal(value) {
           if (value == 'show') {
                 document.getElementById('betalversion').style.display = 'block';
                 document.getElementById('gratisversion').style.display = 'none';
           }
           else {
                  document.getElementById('betalversion').style.display = 'none';
                 document.getElementById('gratisversion').style.display = 'block';
            }
                }
       </script>

       <script type="text/javascript">
         function gratis(value) {
               if (value == 'show') {
                  document.getElementById('betalversion').style.display = 'none'; 
                  document.getElementById('gratisversion').style.display = 'block';
                }
                else {
                  document.getElementById('gratisversion').style.display = 'none';
                  document.getElementById('betalversion').style.display = 'block'; 
                }
          }
        </script>

答案 1 :(得分:0)

 <script type="text/javascript">
var beta=document.getElementById('betalversion');
var grati=document.getElementById('gratisversion');
            function betal(value) {
               beta.style.display = 'none';
               grati.style.display = 'none';
            if (value == 'show') { 
              beta.style.display = 'block'; }
            else { beta.style.display = 'none'; }
        }

    </script>

    <script type="text/javascript">
        function gratis(value) {
             beta.style.display = 'none';
               grati.style.display = 'none';
            if (value == 'show') { grati.style.display = 'block'; }
            else { grati.style.display = 'none'; }
        }
    </script>

在切换中隐藏两个div