简体   繁体   English

如何在日期选择器中显示下一个和上一个月的名称,而不只是箭头<,>

[英]How to show next and previous month names in datepicker instead of just arrows <,>

This is my code: https://codepen.io/bskousen/pen/osEJi 这是我的代码: https : //codepen.io/bskousen/pen/osEJi

 $(function() {
    $( "#datepicker" ).datepicker();
 });

I want to show next and previous month names instead of <,>. 我想显示下个月和上个月的名称,而不是<,>。 Is this possible in Jquery datepicker? 在jQuery datepicker中这可能吗? If it is not possible then is it possible in any other datepicker like Bootstrap datepicker? 如果不可能,那么是否可以在其他任何日期选择器(如Bootstrap日期选择器)中使用呢?

Any plugin is fine and I am not very rigid on using Jquery datepicker. 任何插件都很好,我对使用Jquery datepicker并不是很严格。

Updated answer: 更新的答案:

As I said, I've been looking for a better solution. 正如我所说,我一直在寻找更好的解决方案。
And I found basically the same as Adeel. 我发现与Adeel基本相同。

But, you can make more style modifications to get to something where texts fits correctly. 但是,您可以进行更多的样式修改,以使文本正确放置。
Here is the snippet I ended up with: 这是我最后得到的代码段:

 $(function() { $('#datepicker').datepicker({ navigationAsDateFormat: true, nextText: 'MM', prevText: 'MM' }); }); 
 .container { width: 600px; padding: 20px; margin: auto; background: #ddd; } .ui-datepicker-prev, .ui-datepicker-next { width: 4em !important; } .ui-datepicker-title > span { font-size: .85em !important; } .ui-datepicker-prev > span, .ui-datepicker-next > span { text-indent: 0; margin: 0 !important; text-align: center; height: inherit !important; width: inherit !important; background: 0 !important; left: 0 !important; transform: translateY(-25%); font-size: .65em; font-weight: normal; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> <link rel="stylesheet prefetch" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css"> <div class="container"> <p>This is a datepicker example using jquery, jquery ui, and jquery css</p> <form> Date: <input id="datepicker"> </form> </div> 

Hope it helps. 希望能帮助到你。


Old answer 旧答案

I am not aware of any easy way to change the next and previous icons into month names in the jQueryUI datepicker. 我不知道在jQueryUI datepicker中将下一个和上一个图标更改为月份名称的任何简便方法。

But, there is a built-in functionality to show the month in the tooltip instead of "previous" and "next". 但是,有一个内置功能可以在工具提示中显示月份,而不是“上一个”和“下一个”。
Here it is: 这里是:

 $(function() { $('#datepicker').datepicker({ navigationAsDateFormat: true, nextText: 'MM', prevText: 'MM' }); }); 
 .container { width: 600px; padding: 20px; margin: auto; background: #ddd; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> <link rel="stylesheet prefetch" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css"> <div class="container"> <p>This is a datepicker example using jquery, jquery ui, and jquery css</p> <form> Date: <input id="datepicker"> </form> </div> 

I'll look for a better solution. 我会寻找更好的解决方案。

Anyway, I hope it helps. 无论如何,我希望它会有所帮助。

I've added navigationAsDateFormat to get month names which is a built-in feature of Datepicker (but those names can be appeared only in tooltip), but after some tweaking to your Codepen I'm able to display names instead of icons. 我已经添加了navigationAsDateFormat来获取月份名称,这是Datepicker的内置功能(但是这些名称只能显示在工具提示中),但是在对Codepen进行一些调整之后,我可以显示名称而不是图标。

jQuery jQuery的

$("#datepicker").datepicker({
    navigationAsDateFormat: true,
    nextText: 'MM',
    prevText: 'MM'
});

CSS CSS

.ui-icon {
    text-indent: 0;
    color: #000;
    width: 70px;
    background: 0 !important;
}

Please check this Simple jQuery date picker (replace icons with month names) 请检查此简单的jQuery日期选择器(将图标替换为月份名称)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JQuery UI datepicker如何显示月导航的下一个上一个箭头? - JQuery UI datepicker how to show next prev arrows for month navigation? jQueryUI 日期选择器不显示下一个前一个三角形箭头 - jQueryUI datepicker not showing next previous triangle arrows 如何用箭头而不是下一个上一个制作猫头鹰旋转木马 - How to make a owl carousel with arrows instead of next previous 如何在Bootstrap日期选择器中获得下个月上个月而不是下一个上一个图标? - How to get next month Previous month in Bootstrap date picker instead of next previous icon? Gijgo Datepicker上个月和下个月的图标更改 - Gijgo Datepicker previous and next month icon change vue-bootstrap-datetimepicker 中缺少指向下个月和上个月的箭头? - arrows to next and previous month are missing in vue-bootstrap-datetimepicker? 在 MUI DatePicker 中显示仅一个月后 - Show just a month from now in MUI DatePicker jQuery Datepicker从当前月份删除上个月或下个月的日期 - Jquery Datepicker remove days of previous or next month from the current month 如何为图库添加上一个和下一个箭头? - How to add previous and next arrows for image gallery ? 使用后不会显示下一个和上一个箭头 - next and previous arrows don't show up after using
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM