【问题标题】:Calender not showing after clicking on icon but showing after clicking on input field单击图标后日历未显示,但单击输入字段后显示
【发布时间】:2017-02-26 12:39:02
【问题描述】:

我使用了 bootstrap 的 datepicker 插件。但是,我点击图标后没有显示日历。我必须点击输入字段才能显示日历?

 <label for="dob" class="col-md-4 control-label">Date Of Birth</label>
      <div class="col-md-6">
          <div class="input-group date">
              <input id="dob" class="form-control datepicker" placeholder="2012-02-12" type="text" name="dob" value="{{ old('dob') }}" required autofocus>
          <div class="input-group-addon">
              <span class="glyphicon glyphicon-th"></span>
          </div>
     </div>

脚本:

  $('.datepicker').datepicker({
          format: 'yyyy-mm-dd'
    });

在我将 id 添加到父元素之后:

<label for="dob" class="col-md-4 control-label">Date Of Birth</label>
          <div class="col-md-6">
              <div class="input-group date" id="datepicker">
                  <input id="dob" class="form-control datepicker" placeholder="2012-02-12" type="text" name="dob" value="{{ old('dob') }}" required autofocus>
              <div class="input-group-addon">
                  <span class="glyphicon glyphicon-th"></span>
              </div>
         </div>

和脚本:

$('#datepicker').datepicker({
      format: 'yyyy-mm-dd'
});

控制台报错:

未捕获的类型错误:无法读取未定义的属性“拆分”

这个确切的Working fiddle 也不起作用。

【问题讨论】:

  • @rasmeister 是的,但在控制台中显示错误Uncaught TypeError: Cannot read property 'split' of undefined

标签: javascript jquery twitter-bootstrap datepicker


【解决方案1】:
 $('.glyphicon-th').click(function() {
$(".datepicker").focus();
 });

试试这个来聚焦日期选择器

【讨论】:

  • 这行得通。但它不应该在不添加的情况下显示吗?
【解决方案2】:

Bootstrap 没有自己的日期选择器。根据我的猜测,您必须使用 https://bootstrap-datepicker.readthedocs.io/en/latest/ 。 如果是这样,您必须拥有日历才能工作的所有依赖项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    相关资源
    最近更新 更多