2016-07-22 58 views

回答

0

你可以試試這個(使用jQuery隱藏和顯示):


你必須首先包括jQuery的在你的文件,使其工作;

HTML:

  <script src="jquery-2.1.4.js" type="text/javascript"></script> 

     <input type="radio" class="radiobutton" name="select" value="yes" /> yes 
     <input type="radio" class="radiobutton" name="select" value="no" />no 
     <input type="text" name="name" id="name" value="" /> 

工作實施例https://jsfiddle.net/prohit0/zfjsmn59/22/

SCRIPT:

 <script> 

     $(document).ready(function(e) { 
      $('input[type="radio"]').click(function(){ 

      if($(this).attr("value")=="yes"){ 
       //id is the id of the elemnt to hide 
       $('input[id="name"]').show(); 
      }else { 
      $('input[id="name"]').hide(); 
     } 
     }); 
    }); 
    </script> 

http://www.tutorialrepublic.com/faq/show-hide-divs-based-on-radio-button-selection-in-jquery.php