代码之家  ›  专栏  ›  技术社区  ›  ashura91

如何在模式中修复datepicker中的月/年组合框?

  •  -1
  • ashura91  · 技术社区  · 7 年前

    我在模式中使用日期选择器。但是,我无法更改日期选择器中的月/年。

    我看过这个 question 。但所选答案不是我要找的答案。

    这里有一个 fiddle 基于上述问题。

    我的html:

    <input type="text" id="sel_periode_1" readonly="readonly" class="form-control" />

    3 回复  |  直到 7 年前
        1
  •  2
  •   ashura91    7 年前

    似乎我无法选择月/年,因为我使用 $('#myModal').modal('show');

    我的解决方案是将其更改为 $('#myModal').fadeIn('fast');

        2
  •  0
  •   Gangani Roshan Alex S    7 年前

    HTML代码:

       <!-- Button to trigger modal -->
        <a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
    
        <!-- Modal -->
        <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">Modal header</h3>
          </div>
          <div class="modal-body">
            <div id="datetimepicker1" class="input-append date">
              <input data-format="dd/MM/yyyy" type="text"></input>
              <span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
            </div>
          </div>
          <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
          </div>
        </div>
    

    JQuery代码:

    $(function() {
      $('#datetimepicker1').datetimepicker({
      });
    });
    
        3
  •  0
  •   Abhilash Ravindran C K    7 年前

    按如下方式更改您的输入,

    <input type="text" id="sel_periode_1" readonly="readonly" class="form-control datepicker" />
    

    将以下代码添加到脚本中,

    $('.datepicker').datepicker({
                    changeMonth: true,
                    changeYear: true
                    // set properties as your requirement
     });
    

    注意:添加对的引用 jquery.min.js ,则, jquery-ui.min.js jquery-ui.css 对于 datepicker 工作。

    Fiddle Demo Here