。#datepicker不起作用是错误和未单击图标?

时间:2018-11-03 08:42:00

标签: javascript jquery html datepicker

enter image description here

即使在下面的代码之后,也没有单击该图片和图标:

    <div class="col-sm-6 col-sm-6">
                            <div class="form-group">
                                <div class='input-group date' id='datetimepicker9'>
                                    <input type='text' class="form-control" />
                                    <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                            </div>
                        </div>                      
                    </div>

                            <script type="text/javascript">
                                $(function () {
                                    $('#datetimepicker10').datetimepicker({
                                        viewMode: 'years',
                                        format: 'MM/YYYY'
                                    });
                                });
                            </script>

2 个答案:

答案 0 :(得分:0)

将您的id datetimepicker9更改为datetimepicker10

 <div class="col-sm-6 col-sm-6">
                            <div class="form-group">
                                <div class='input-group date' id='datetimepicker10'>
                                    <input type='text' class="form-control" />
                                    <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                            </div>
                        </div>                      
                    </div>

                            <script type="text/javascript">
                                $(function () {
                                    $('#datetimepicker10').datetimepicker({
                                        viewMode: 'years',
                                        format: 'MM/YYYY'
                                    });
                                });
                            </script>

答案 1 :(得分:0)

  1. 更改:将datetimepicker10更改为datetimepicker9
  2. 我猜您忘了添加jquery-ui(css + js)。

    确保在运行jquery.js脚本后运行jquery-ui.js

    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>

    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

您可以看到一个有效的jsfiddle here