jquery - Bootstrap datetimepicker 出现在窗口的左上角

标签 jquery css asp.net-mvc twitter-bootstrap

我正在使用天知道在哪里的日期时间选择器,但它恰好存在于一组具有命名约定 bootstrap-datetimepicker-min.js.css 的文件中。我假设这是 Bootstrap 小部件之一,那么,我认为它基于 jQuery UI 的日期时间选择器。无论如何,该 API 与 jQuery UI 日期时间选择器非常相似。

所以,我有这段代码,但是一旦我点击日期输入字段,日期时间选择器就会出现在窗口的左上角,然后它也不会消失。

ThePage.cshtml

...

<!-- stuff -->

<div class="form-group">
            @Html.LabelFor(model => model.FromDate, htmlAttributes: new { @class = "control-label col-md-2"})
            <div class="col-md-10">
                <input type="text"class="form-control" id="dtFromDate" name="FromDate" />
                @Html.ValidationMessageFor(model => model.FromDate, "", new { @class = "text-danger" })
            </div>
        </div>

@section scripts {
    <script type="text/javascript">
        $(document).ready(Initialize);

        function Initialize()
        {
            $('#dtFromDate').datetimepicker();
            $('#dtToDate').datetimepicker();
        }
    </script>
}

布局页面包含包含正确的 JavaScript 和 CSS 文件的 include 语句:

Layout.cshtml

<!-- on the top of the page somewhere -->
@Styles.Render("~/Content/css")

...
<!-- stuff -->

<!-- at the bottom of the layout page -->
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/components")
@RenderSection("scripts", required: false)

BundleConfig.cs

bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/site.css",
                      "~/Content/Calendar/css/bootstrap-datetimepicker.min.css",
                      "~/Content/select2/css/select2.min.css"
                      ));

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"
                      ));

bundles.Add(new ScriptBundle("~/bundles/components").Include(
                "~/Content/Calendar/js/bootstrap-datetimepicker.min.js",
                      "~/Content/select2/js/select2.full.min.js",
                      "~/Content/select2/js/i18n/en.js"
                ));

最佳答案

这显然不理想,但这是一个适用于 CSS 的快速修复

span.select2-container[style='position: absolute; top: 0px; left: 0px;'] {
    display: none;
}

关于jquery - Bootstrap datetimepicker 出现在窗口的左上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34765942/

相关文章:

jquery - 使用 jQuery 重置选择框值

javascript - ajax 可以使 Web 应用程序有状态吗?

javascript - 如何从asp.net mvc中的 Controller 传递json格式的chart.js图表​​数据对象

javascript - 存储在 HTML5 存储中的 Bootstrap 崩溃的当前状态

JavaScript:单击时如何更改元素的可见性?

php - jQuery Ajax Json 响应 - 检查是否为 null

css - 在 div 中居中文本

HTML5 : Sticky footer, 标题和文章

jquery - 图像在滚动和 fullPage.js 上变化

c# - ountputcache 属性 sqldependency mvc 中的多个表