简体   繁体   English

jQuery UI Datepicker的多个日期输入

[英]Multiple date inputs for jquery UI datepicker

I have a datepicker, and I need to be able to enter a date manually in multiple different formats. 我有一个日期选择器,我需要能够以多种不同的格式手动输入日期。 For example, for May 7, 2015, I need to be able to enter: 例如,对于2015年5月7日,我需要输入:

05/07/2015 05072015 050715 5715 2015年5月7日05072015 050715 5715

I understand how to format all these above based off of the the jquery docs, but I cannot figure out how to make the input box take multiple different dates. 我了解如何根据jquery文档设置上述所有格式,但是我无法弄清楚如何使输入框采用多个不同的日期。 I can change the format to any one of these individually, which will allow me to type in that specific format, but I can only do this once by defining the "dateFormat". 我可以将格式分别更改为任何一种,这将允许我键入该特定格式,但是只能通过定义“ dateFormat”来执行一次。

I found another page where the same problem seems to have been answered, but after many attempts, I cannot figure out how to fit it into my code successfully, here is the link to this page: 我找到了另一个页面,似乎已经回答了相同的问题,但是经过多次尝试,我无法弄清楚如何将其成功地放入我的代码中,这是此页面的链接:

Datepicker and allowing multiple input formats 日期选择器并允许多种输入格式

How do I fit that solution into the following code: 我如何将该解决方案放入以下代码中:

<h3>Date Selection</h3>
<label for="from">From</label>
<input type="text" id="from" name="from" />
<input type="text" id="altdate" />
<label for="to">to</label>
<input type="text" id="to" name="to" />
<script>
    $(function() {
        $( "#from" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 2,
            onClose: function( selectedDate ) {
                $( "#to" ).datepicker( "option", "minDate", selectedDate );
            }
        });
        $( "#to" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 2,
            onClose: function( selectedDate ) {
                $( "#from" ).datepicker( "option", "maxDate", selectedDate );
            }
        });
    });
</script>

I have been stuck on this for days, any help is greatly appreciated!! 我已经坚持了好几天,任何帮助都将不胜感激!

Please find working fiddle 请找工作提琴

It is created based on jQuery Datepicker that supports multiple formats 它基于支持多种格式的jQuery Datepicker创建

the only thing you have to remember is to set constraint input flag as false 您唯一需要记住的是将约束输入标志设置为false

$(function() {
  $("#datepicker").datepicker({
    constrainInput: false
  })
});

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

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