【问题标题】:JQuery UI datepicker not working in ChromeJQuery UI 日期选择器在 Chrome 中不起作用
【发布时间】:2015-12-31 04:47:42
【问题描述】:

我在我的 asp.net MVC 应用程序中使用 Jquery UI 日期选择器。在 IE 中一切正常,但在 Chrome 中,默认日期选择器也是可见的,当我使用 JQuery UI 时,它不会将日期添加到框中。

我在这里有几个选项作为可能的解决方案,但没有任何效果。

ViewModel 是:

    [Required]
    [Display(Name = "Date of Birth")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy/MM/dd}", ApplyFormatInEditMode = true)]
    public DateTime DateOfBirth { get; set; }

视图是:

            <div class="form-group">
                <div class="row">
                    <div class="col-md-3 col-md-offset-1">
                        @Html.LabelFor(model => model.DateOfBirth, htmlAttributes: new { @class = "control-label" })
                        @Html.EditorFor(model => model.DateOfBirth, new { htmlAttributes = new { @class = "form-control", placeholder = "01/12/80" } })
                        @Html.ValidationMessageFor(model => model.DateOfBirth, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>

日期选择器的脚本是:

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/bootstrap")
<script type="text/javascript">
    $("#DateOfBirth").datepicker({
        format: "yyyy/MM/dd",
        startDate: "-120y",
        endDate: "-10y",
        startView: 2,
        calendarWeeks: true,
        defaultViewDate: { year: 1975, month: 01, day: 01 }
    });
</script>
}

我不能是唯一需要解决这个问题的人,希望它已经解决了。谢谢

【问题讨论】:

    标签: jquery asp.net-mvc datepicker


    【解决方案1】:

    尝试禁用默认日期选择器。看到这个帖子:Disable native datepicker in Google Chrome

    【讨论】:

    • 不幸的是@Marcus Abrahao并没有改变
    • 您是否检查了元素以确保 DateOfBirth 是他的 id?
    • 好的,对不起..我想念你的问题。我猜你的输入是输入日期,对吗?所以你必须禁用默认的日期选择器
    • 如果是这样...试试这个帖子stackoverflow.com/questions/11320615/…
    • 你的意思是使用类和占位符吗? @Html.TextBoxFor(model => model.DateOfBirth, new { @class= "form-control", placeholder = "01/12/80" } )
    猜你喜欢
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 2010-09-28
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多