简体   繁体   中英

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:

05/07/2015 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. 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".

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

the only thing you have to remember is to set constraint input flag as false

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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