我有一個輸入字段,只有在選中「Other」選項時纔會顯示。當我取消選中「其他」複選框時,輸入字段會淡出,但我還希望輸入字段可以淡出,而不是取消選中「其他」複選框,然後選中同一組的另一個複選框。因此,除非選中「其他」,否則「其他」輸入字段不可見。我有JavaScript部分工作,但是當我檢查另一個複選框時,「其他」輸入字段保持可見。檢查不同的複選框隱藏輸入字段
HTML
<input type="checkbox" id="residence_check" name="found"/>
<label for="residence_check">
Residence
</label>
<input type="checkbox" id="tradeshow_check" name="found"/>
<label for="tradeshow_check">
Tradeshow
</label>
<input type="checkbox" id="office_check" name="found"/>
<label for="office_check">
Office Building
</label>
<input type="checkbox" id="check_other" value="found_other" name="found"/>
<label for="check_other">
Other
</label>
<input type="text" id="check_input" placeholder="Other"/>
的Javascript
$('#check_other').change(function() {
if($(this).is(":checked")) {
$('#check_input').fadeIn();
} else {
$('#check_input').fadeOut('fast');
}
});
我剛剛更改爲輸入[type = checkbox],它的效果很好。謝謝! – user2736472