How can I disable month selection in the jQuery datepicker?

后端 未结 4 832
遇见更好的自我
遇见更好的自我 2020-12-10 07:08

I am trying disable the left/right buttons that allow the user to change months. I\'ve removed the drop down list of months but can\'t get rid of the buttons.



        
4条回答
  •  没有蜡笔的小新
    2020-12-10 07:35

    You can effectively disable them using stepMonths by making them go nowhere when clicked, like this:

    $("#date").datepicker({
      changeMonth: false,
      changeYear: false,
      dateFormat: 'dd/mm/yy',
      duration: 'fast',
      stepMonths: 0
    });
    

    You can give it a try here

    Or, you could remove the buttons like this:

    $("#date").datepicker({
      changeMonth: false,
      changeYear: false,
      dateFormat: 'dd/mm/yy',
      duration: 'fast'
    }).focus(function() {
      $(".ui-datepicker-prev, .ui-datepicker-next").remove();
    });​
    

    You can give that a try here, this works because the default showOn option is focus, if you're using a different event, just bind to that after the .datepicker() call (so its event runs first, you can't hide what isn't created yet).

提交回复
热议问题