how to show a jquery datepicker on button click

后端 未结 5 1276
清歌不尽
清歌不尽 2020-12-17 00:20

I want to show a datepicker only on button click


$(\"#day\").datepicker();

the above l

相关标签:
5条回答
  • 2020-12-17 00:38

    You can attach a button as a trigger to the jQuery DatePicker as mentioned below,

    <script type="text/javascript>"
      $( function() {
          $( "#datepicker" ).datepicker({
              showOn: "button",
              buttonImage: "https://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
              buttonImageOnly: true,
              buttonText: "Select date"
          });
        });
        </script>
    

    Click on the following link for a working fiddle example

    https://jsfiddle.net/anjanasilva/rtt25a1m/

    0 讨论(0)
  • 2020-12-17 00:46

    You need to initialize datepicker for your input field first

    $('#input_filed').datepicker();
    

    Then you need add trigger for button

    $('#button').click(function() {
          $('#input_filed').datepicker('show');
    });
    
    0 讨论(0)
  • 2020-12-17 00:52

    Try putting

    $("#hiddenField").datepicker({
        showOn: 'button',
        buttonText: 'Choose Date',
        dateFormat: 'dd/mm/yy',
        constrainInput: true
    });
    

    in $(document).ready(function(){}); function.

    Hope this helps.

    0 讨论(0)
  • 2020-12-17 00:57

    try following :

    $("#day").click(function() {
            $("#hiddenField").datepicker("show");
        });
    

    single quotes doesn't work.

    hope this helps.

    0 讨论(0)
  • 2020-12-17 00:59

    You can do this with the built-in showOn function:

    $( "#hiddenField" ).datepicker({
        showOn: "button",
        buttonText: "day"
    });
    

    JSFiddle: http://jsfiddle.net/Uv8V4/

    Reference: http://jqueryui.com/datepicker/#icon-trigger

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