jquery: using two datepicker with two fields ( field 1 , field2 + 1 day ) like booking.com

前端 未结 3 1237
离开以前
离开以前 2021-01-16 04:51

How r u?

I have two datepickers with two fields

I want when the user choosing (From) the second field ( TO ) will be next

3条回答
  •  心在旅途
    2021-01-16 05:36

    I have created a working JSFiddle for you:

    http://jsfiddle.net/jirilmongeorge/f329k/26/

    Here is the javascript code:

    $(document).ready(function() {
        $( "#from" ).datepicker({
        defaultDate: "+1D",
        changeMonth: true,
        numberOfMonths: 1,
        dateFormat:"dd-mm-yy",
        minDate: "+1D",
        showOn: "button",
        buttonImage: "http://keith-wood.name/img/calendar.gif",
        buttonImageOnly: true , 
        onSelect: function(dateText, inst){
            var d = $.datepicker.parseDate(inst.settings.dateFormat, dateText);
            d.setDate(d.getDate()+1);
            $("#to").val($.datepicker.formatDate(inst.settings.dateFormat, d));
        }
    
       });
    
       $( "#to" ).datepicker({
            showOn: "button",
            buttonImage: "http://keith-wood.name/img/calendar.gif",
            buttonImageOnly: true,
            changeMonth: true,
            changeYear: true
        });
    
      $('#from').attr('readonly', true);
      $('#to').attr('readonly', true);
    });
    

提交回复
热议问题