jQuery UI datepicker无法正常工作? [英] jQuery UI datepicker not working?

查看:83
本文介绍了jQuery UI datepicker无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web应用程序中显示了jQuery ui datepicker,但是当我选择一个日期时,它什么也没做。并且默认的Html5 datepicker仍在显示。

I have the jQuery ui datepicker showing up in my web app, but when I go to choose a date, it doesn't do anything. And the default Html5 datepicker is still showing up.

我的日期选择器图片

如何禁用jQuery Ui datepicker的Html5?

How can I disable the Html5 one for the jQuery Ui datepicker to work?

我的代码:

Create.cshtml

 @Html.LabelFor(model => model.EnrollmentDate, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.EnrollmentDate, new { htmlAttributes = new { @class = "form-control", @id = "datepicker" } })
                    @Html.ValidationMessageFor(model => model.EnrollmentDate, "", new { @class = "text-danger" })

........

@section Scripts {
<script>
    $(document).ready(function(){
        $('#datepicker').datepicker({
        dateFormat: 'dd-mm-yy'
       });
    });
</script>        
    @Scripts.Render("~/bundles/jqueryval")
}


推荐答案

我偶然发现此问题的原因是因为我将jQuery UI用于日期选择器。出于某种原因,它在基于Chromium的浏览器上无法正常工作。

The reason I stumbled across this question is because I was using the jQuery UI for the datepickers. For some reason, it wasn't working properly on Chromium-based browsers.

要使其正常运行,只有在浏览器上,我才必须将类型更改为文本

To make them work, I had to change the type to 'text' only if the browser was Chromium-based.

为此,我只写了以下内容:

To do so, I just wrote the following:

function fixDatepickers(){
    if (window.chrome !== undefined) {
        $('#ID_of_datepicker')[0].type = 'text';
    }
}

,然后在日期选择器所在的HTML页面中将其调用不能像这样工作:

and then called it in the HTML page where the datepickers are not working like this:

<script src="file_with_new_func.js"></script>
<script type="text/javascript">$(document).ready(fixDatepickers());</script>

像魅力一样工作!

这篇关于jQuery UI datepicker无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆