Getting value from JQUERY datepicker

前端 未结 10 1857
故里飘歌
故里飘歌 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条回答
  • $('div#someID').datepicker({
       onSelect: function(dateText, inst) { alert(dateText); }
    });
    

    you must bind it to input element only

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

    I needed to do this for a sales report that allows the user to choose a date range. The solution is similar to another answer, but I wanted to provide my example just to show you the practical real world use that I applied this to:

    var reportHeader = `Product Sales History Report for ${$('#FromDate').val()} to ${$('#ToDate').val()}.` ;
    ```
    
    0 讨论(0)
  • 2020-11-29 08:34

    You can also try this.

    $('#datepickerID').val();
    

    This is the simplest way.

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

    You could do it as follows - with validation just to ensure that the datepicker is bound to the element.

    var dt;
    
    if ($("div#someID").is('.hasDatepicker')) {
        dt = $("div#someID").datepicker('getDate');
    }
    
    0 讨论(0)
  • 2020-11-29 08:51

    see tag input example :

    <div class="input-group date" data-target-input="nearest">
                            <input type="text" class="form-control datetimepicker-input form-control-sm" data-target="#dt_expdate" id="dt_expdate" />
                            <div class="input-group-append" data-target="#dt_expdate" data-toggle="datetimepicker">
                                <div class="input-group-text form-control-sm"><i class="fa fa-calendar"></i></div>
                            </div>
                        </div>
    

    acess to get & assign value from

    id="dt_expdate"
    

    get value:

    var date= $("#dt_expdate").val();
    

    assign value:

    $("#dt_expdate").val('20/08/2020');
    
    0 讨论(0)
  • 2020-11-29 08:52

    You could remove the name attribute of this input, so it won't be submited.

    To access the value of this controll:

    $("div#someID").datepicker( "getDate" )
    

    and your may have a look at the document in http://jqueryui.com/demos/datepicker/

    0 讨论(0)
提交回复
热议问题