简体   繁体   English

jQuery UI日期选择器重点

[英]JQuery UI Date Picker Focus

I have implemented JQuery UI Datepicker but have two problems with the functionality. 我已经实现了JQuery UI Datepicker,但是在功能上存在两个问题。 Implemetation code is below 实施代码如下

<script type="text/javascript">
    $(document).ready(function(){
        $(".datepicker").datepicker({
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true,
            yearRange: '-100y:c+nn'
        });
    });
</script>

1st Issue: On a standard page this seems to work fine although the calendar loses focus when a day is picked. 第一个问题:在标准页面上,这似乎很好用,尽管选择某天后日历会失去焦点。 As I am from the UK and focusing on UK users, our normal date formatting is to start with the day->then select month-> then select year. 由于我来自英国,并且主要针对英国用户,因此我们正常的日期格式是从日期->然后选择月份->然后选择年份开始。 As a usability issue it appears most users I have tested this on start by inputting the day hence where the datepicker disappears. 作为可用性问题,看来大多数用户在开始输入日期之后就对它进行了测试,从而使日期选择器消失了。 Is there an easy way to format the ui to lose focus on clicking on the year ? 是否有一种简单的方法来设置ui格式,以使其不再关注单击年份?

Another issue I am having is combining the ui with a bootstrap modal. 我遇到的另一个问题是将ui与引导程序模式结合在一起。 There seems to be a conflict stopping the month and year dropdowns functioning correctly. 似乎存在冲突,导致月份和年份下拉列表无法正常运行。 I have tried altering the z-index of the date picker css with little success. 我尝试更改日期选择器css的z索引,但收效甚微。

If you're already using jquery-ui for the date picker, why not go ahead and use it for the modal dialog as well? 如果您已经将jquery-ui用于日期选择器,为什么不继续将其也用于模式对话框呢? It may simplify your build a little if you only leverage one set of libraries. 如果仅利用一组库,则可能会稍微简化构建过程。

You could display the date picker "inline", embedded in the modal instead of in an overlay and then use the altField option to populate the field of your form. 您可以显示日期选择器“内联”,嵌入在模式中而不是重叠中,然后使用altField选项填充表单的字段。

Something like this: 像这样:

Working Example 工作实例

<form>Date:
    <input class="date"></input>
    <div id="dialog-message" title="Pick A Date">
        <div class="datepicker"></div>
    </div>
</form>

$('.date').click(function () {
    $(".datepicker").datepicker({
        dateFormat: 'dd/mm/yy',
        changeMonth: true,
        changeYear: true,
        yearRange: '-100y:c+nn',
        altField: ".date"
    });
    $("#dialog-message").dialog({
        modal: true,
        resizable: false,
        width: 340,
        buttons: {
            Ok: function () {
                $(this).dialog("close");
            }
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM