Getting value from JQUERY datepicker

前端 未结 10 1858
故里飘歌
故里飘歌 2020-11-29 07:56

If I want to display the JQUERY UI datepicker inline by attaching it to a DIV like $(\"div#someID\").datepicker() - how do I access the chosen date? I assume if

相关标签:
10条回答
  • 2020-11-29 08:53

    You can use the getDate method:

    var d = $('div#someID').datepicker('getDate');
    

    That will give you a Date object in d.

    There aren't any options for positioning the popup but you might be able to do something with CSS or the beforeShow event if necessary.

    0 讨论(0)
  • 2020-11-29 08:56

    If your selected elements are not one, you need use this way:

    $('[type="date"]').datepicker();
    $('[type="date"]').change(function() {
        var date = $(this).datepicker("getDate");
        console.log(date);
    });
    
    0 讨论(0)
  • 2020-11-29 08:59

    If you want to get the date when the user selects it, you can do this:

    $("#datepicker").datepicker({
        onSelect: function() { 
            var dateObject = $(this).datepicker('getDate'); 
        }
    });
    

    I am not sure about the second part of your question. But, have you tried using style sheets and relative positioning?

    0 讨论(0)
  • 2020-11-29 08:59

    To position the datepicker next to the input field you could use following code.

    $('#datepicker').datepicker({
        beforeShow: function(input, inst)
        {
            inst.dpDiv.css({marginLeft: input.offsetWidth + 'px'});
        }
    });
    
    0 讨论(0)
提交回复
热议问题