0
有一個(希望)簡單的問題,我希望根據以前的下拉選擇選項自動顯示輸入框。基於下拉選擇的HTML動態輸入框
所有這一切都很新,所以任何幫助,非常感謝!
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<legend><b>Did Cardio Session?</b></legend>
<p>
<select name = "cardio" id = "cardio">
<option value = "No" selected>No</option>
<option value = "Yes">Yes</option>
</select>
<div id = "cardioyes" style = "display:none;">
<label for="How Long?">How Long?</label>
<input type = "text" name = "duration" />
</div>
</p>
<script>
$('#cardio').change(function(){
selection = $(this).val();
switch(selection)
{
//show the <div> or not
case 'Yes':
$('#cardioyes').show();
break;
default:
$('#cardioyes').hide();
break;
}
});
</script>
你確實有代碼;有什麼問題? –
它的工作我猜,也許你想'輸入'在頁面加載時更新? – kukkuz