2014-10-17 33 views
0

我創建一個複選框及其2個依賴的輸入字段,當我檢查複選框時出現2個輸入字段,然後我寫一些,但是當我取消選中輸入字段無法重置的複選框時該價值並提交。我想要簡單的時候,我取消選中,然後複選框其依賴的輸入字段將其值重置爲默認值。這裏是我的代碼:複選框取決於輸入字段不能復位後取消選中

<input id="return" type="checkbox" value="" name="return">Return Journey 
<div class="bkt_return_journey" id="altway" style="display: none;"> 
<input type="text" name="datebr" id="datepickerr" class="booktaxti_input" /></div> 

<script type="text/javascript"> 
$('#return').live('change', function(){ 

if ($(this).is(':checked')) { 
    $('#altway').show(); 
} else { 
    $('#altway').hide(); 
} 
}); 

</script> 

回答

0
<html> 
<head> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
</head> 

<body> 
    <input id="return" type="checkbox" value="" name="return">Return Journey 
    <div class="bkt_return_journey" id="altway" style="display: none;"> 
    <input type="text" name="datebr" id="datepickerr" class="booktaxti_input" /> 
    </div> 

    <script type="text/javascript"> 

    $(document).ready(function(){ 
     $('#return').on('click', function(){ 

      if ($(this).is(':checked')) { 
      $('#datepickerr').val(''); 
      $('#altway').show(); 
     } else { 
      $('#altway').hide(); 
     } 
     }); 
    }); 


    </script> 
</body> 

希望它可以幫助你

+0

真的感謝它解決我的問題 – kamran 2014-10-20 04:25:49

+0

沒問題希望能幫助別人 – 2014-10-27 07:29:19

0
<input id="return" type="checkbox" value="" name="return">Return Journey 
<div class="bkt_return_journey" id="altway" style="display: none;"> 
<input type="text" name="datebr" id="datepickerr" class="booktaxti_input" /></div> 

<script type="text/javascript"> 
$(document).on('click','#return', function(){ 
    if ($(this).is(':checked')) { 
     $('#altway').show(); 
    } else { 
     $('#altway').hide(); 
    } 
}); 
</script> 
+0

這項工作嘗試這一點。點擊文本框顯示並取消隱藏 – Affan 2014-10-17 09:33:11

0

你可以改變你的代碼如下:

$('#return').on('change', function() { 
    if ($(this).is(':checked')) { 
     $('#datepickerr').val(''); 
     $('#altway').show(); 
    } else { 
     $('#altway').hide(); 
    } 
});