我需要创建一个隐藏的文本框,当用户选择“其他”时可以访问该文本框。这是我的代码。请指教
<script>
$('#sel').change(function() {
$('#other').css('display', ($(this).val() == 'Other') ? 'block' : 'none');
});
});</script>
<div class="form-group">
<label class="control-label col-sm-2">Frequency:</label>
<div class="col-xs-3">
<select id="Regime" name="regime" class="form-control" required="">
<option value="" selected="" disabled="">Please select A regime...</option>
<option value="Once A Day">Once A Day</option>
<option value="BD">BD</option>
<option value="TDS">TDS</option>
<option value="QDS">QDS</option>
<option value="Other">Other (please specify)</option>
</select>
<input type="text" id="other" style="display: none;" />
</div>
</div>
最佳答案
你让它显示:无;在 css 中,然后使用 jQuery 在用户选择其他时显示它。
<style type="text/css">
#textbox{
display: none;
}
</style>
<script type="text/javascript>
$('#Regime').change(funtion(){
if($('#Regime').val() == 'Other'){
$('#textbox').show();
}
});
</script>
但也不要忘记链接 jQuery。 这在你的头标签之间......
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
关于jquery - 创建一个带有选择选项的文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31643110/