【问题标题】:jQuery UI Datepicker - How to have equal width of calendar and input field?jQuery UI Datepicker - 如何使日历和输入字段的宽度相等?
【发布时间】:2018-03-24 23:52:35
【问题描述】:

问题: 日历的初始宽度设置为与输入字段的宽度相同。但是,一旦单击上一个/下一个按钮(更改月份),日历宽度将重置。

可能的解决方案:像这样使用 onChangeMonthYear 函数,但它不起作用:

onChangeMonthYear: function() {
    $('#ui-datepicker-div').outerWidth($('#thedate').outerWidth());
}

HTML:

<div class="box">
  <input id="thedate" type="text" />
</div>

JS:

$(function(){

    $('#thedate').datepicker({
        dateFormat: 'dd-mm-yy',
        beforeShow: function (input, inst) {
            setTimeout(function() {
                inst.dpDiv.outerWidth($('#thedate').outerWidth());
            },0);
        },
    });

});

JSFIDDLE: http://jsfiddle.net/63x6t1d5/

【问题讨论】:

    标签: jquery jquery-ui datepicker jquery-ui-datepicker


    【解决方案1】:

    http://jsfiddle.net/cafp58w6/8/

    $(function(){
      $('#thedate').datepicker({
        dateFormat: 'dd-mm-yy',
        beforeShow: function (input, inst) {
          setTimeout(function() {
            inst.dpDiv.outerWidth($('#thedate').outerWidth());
          }, 0);
        },
      });
    
      $('div.ui-datepicker').on('click',function(){
        $(this).outerWidth($('#thedate').outerWidth());
      });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 2015-07-18
      相关资源
      最近更新 更多