【问题标题】:Bootstrap Datepicker not working in chromeBootstrap Datepicker 在 chrome 中不起作用
【发布时间】:2014-04-02 12:26:56
【问题描述】:

我使用 Jquery 插件 Bootstrap Datepicker。它在 Firefox 中运行良好。此外,它适用于我在谷歌浏览器(版本 33.0.1750.117 m)中的网站的某些页面。但是,有一个文本输入 (name="TravelDate"),此插件不起作用。此文本输入放置在 Bootstrap 模式窗口中。

<script>
$(function () {
    $("#date-trip").datepicker({
        format: "dd.mm.yyyy",
        startDate: new Date(),
        todayBtn: "linked",
        language: "ru",
        autoclose: true
    });
});
</script>

<!-- Modal -->
<div class="modal fade" id="createTripModal" tabindex="-1" role="dialog" aria-labelledby="createTripModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Travel creating</h4>
            </div>

            @using (Html.BeginForm("Create", "Trip", new {ReturnUrl = ViewBag.ReturnUrl}, FormMethod.Post, new {@class = "form-horizontal", role = "form"}))
            {
                @Html.AntiForgeryToken()

                @Html.ValidationSummary(true)
                <div class="modal-body">
                    <label for="date-trip">Date:</label>
                    <input name="TravelDate" type="text" id="date-trip" class="form-control" required autofocus />
                </div>
                <div class="modal-footer">
                    <input type="submit" value="Create" class="btn btn-primary" />
                </div>
            }
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<!-- /.modal -->

Google Chrome 的控制台中没有错误。此插件在其他表单上正常工作很重要。

我很乐意听取任何建议。

【问题讨论】:

  • 我使用的是同一个插件的 1.6.0 版,但它在 Chrome 中不起作用。对我来说,原因是 jQuery 的旧版本。因此,如果有人发现这个问题并且下面的答案不起作用,请尝试升级 jQuery。

标签: jquery google-chrome bootstrap-datepicker


【解决方案1】:

我修复了一个错误。 This post 帮助了我。我在插件代码中更改了这一行(+10 -> +1151):

var zIndex = parseInt(this.element.parents().filter(function() {
                            return $(this).css('z-index') != 'auto';
                        }).first().css('z-index'))+1151;

【讨论】:

    【解决方案2】:

    注意使用&lt;input type="date"....&gt; - 最新版本的 Chrome 有自己的 html5 输入类型字段 "date" 的日期选择器,会干扰 Bootstrap 3 日期选择器。请改用&lt;input type="text"....&gt;。

    【讨论】:

      【解决方案3】:

      请在您的代码中使用此 CSS 以在 Chrome 中显示日期选择器:

      <style>.datepicker{z-index:1200 !important;}</style>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-23
        • 1970-01-01
        • 2015-11-22
        • 2021-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多