jquery - 创建一个带有选择选项的文本框

标签 jquery html css

我需要创建一个隐藏的文本框,当用户选择“其他”时可以访问该文本框。这是我的代码。请指教

         <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/

相关文章:

ajax - 如何将成功行为绑定(bind)到另一个 ajax 表单提交?

jquery - 带有子导航的菜单的垂直滚动条

html - 为什么在页面末尾需要 "Valid XHTML & CSS"通知

css - HTML 模板无法在 outlook 7 上打开,为什么?

html - Go 可以在它所服务的 HTML 文档中捕获点击事件吗?

css - MOODLE - block 的自定义 CSS

css - 清除修复 ie8 和 CSS

javascript - 在资源管理器中防止默认不起作用

javascript - Ajax jquery Post 没有发送参数

html - 缩小按钮的尺寸切割图像而不是缩小尺寸