当有人在以下代码片段的帮助下单击输入时,我使用 jquery ui datepicker 来显示 datepicker。
代码:
$('#datepicker').datepicker();
我遇到的问题是日历应该是前面输入的全宽。
我确实在互联网上搜索并使用了一些代码片段,但没有任何效果。
我的方法:
$('#datepicker').datepicker({
beforeShow: function(input, inst)
{
inst.dpDiv.css({ width: input.width + 'px'});
}
});
在 Fiddle 中,输入的宽度固定为 500px,因此日期选择器宽度也应为 500px 宽。并且日期选择器的宽度应该适应此输入的任何宽度。
最佳答案
您可以使用以下 CSS 调整日历大小:
$('#datepicker').datepicker();
#datepicker,
.ui-datepicker,
.ui-datepicker-header,
.ui-datepicker-calendar {
width: 500px;
}
.ui-datepicker-calendar {
background: dodgerblue;
}
.ui-datepicker-header {
text-align: center;
color: #fff;
background: #000;
}
.ui-datepicker-prev {
float: left;
}
.ui-datepicker-next {
float: right;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<input type="text" id="datepicker">
关于jquery - 自定义 jQuery ui 日期选择器宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37318035/