2014-04-11 28 views
0

我怎樣才能刪除值一旦用戶點擊Yes,並輸入在輸入框的值,而是改變了主意,單擊否選項,但輸入值仍然存在刪除輸入值,如果選項沒有被點擊

<div class="control-group"> 
    <label class="control-label" for="radios">Do you offer rented call center seating on a monthly basis?</label> 
    <div class="controls"> 
     <label class="radio" for="yes"> 
      <input type="radio" name="radios-1" id="radios-1" value="Yes">Yes</label> 
     <label class="radio" for="no"> 
      <input type="radio" name="radios-1" id="radios-1" value="No">No</label> 
    </div> 
</div> 
<div class="form-group" style="display:none;" id="seatnumber"> 
    <label class="control-label" for="name">How many seats do you have available?</label> 
    <div class="input-group"> <span class="input-group-addon"><i class="fa fa-user"></i></span> 

     <input type="text" class="form-control input-normal" placeholder="Enter number of seats here..." name="monthly_rental" id="monthly_rental"> 
    </div> 
</div> 

JS

 $('input[name|="radios-1"]').change(function() { 

     if($(this).val()=='Yes') { 
      $('#seatnumber').fadeIn(); 

     } else { 

      $('#seatnumber').fadeOut(); 
     } 
    }); 

回答

2

試試這個:

$('input[name|="radios-1"]').change(function() { 
     if($(this).val()=='Yes') { 
      $('#seatnumber').fadeIn(); 
     } else { 
      $('#seatnumber input').val(''); // remove value when user click No 
      $('#seatnumber').fadeOut(); 
     } 
}); 

DEMO

0
$('input[name|="radios-1"]').change(function() { 
     $('#monthly_rental').val(''); 
     if($(this).val()=='Yes') { 
      $('#seatnumber').fadeIn(); 

     } else { 

      $('#seatnumber').fadeOut(); 
     } 
    }); 

演示:

http://jsfiddle.net/7Te9d/

相關問題