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