添加“st,nd,rd,th"到 jquery 日期选择器 [英] Adding "st, nd, rd, th" to jquery datepicker
本文介绍了添加“st,nd,rd,th"到 jquery 日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 st,nd,rd,th 添加到日期格式.. 即 11 月 19 日或 12 月 2 日等
How can I add st,nd,rd,th to date format.. i.e. November 19th, or December 2nd, etc.
目前,我有以下代码
$( "#datepicker" ).datepicker({
altField: "#alternate",
altFormat: "DD, MM d ",
minDate: +0
});
推荐答案
因为 formatDate() 没有那个选项.
Since formatDate() doesn't have that option.
是的,你是对的,抱歉我的回答没有帮助你,我是新来的.我希望这次能有所帮助:)
Yes, you were right, sorry my answer didn't help you, I'm new to SO. I hope it helps this time :)
向 datepicker init 添加一个 onSelect 函数,如下所示:
Add an onSelect function to datepicker init, something like this:
$("#datepicker").datepicker({
altField: "#alternate",
altFormat: "DD, MM d",
minDate: +0,
onSelect: function(dateText, inst) {
var suffix = "";
switch(inst.selectedDay) {
case '1': case '21': case '31': suffix = 'st'; break;
case '2': case '22': suffix = 'nd'; break;
case '3': case '23': suffix = 'rd'; break;
default: suffix = 'th';
}
$("#alternate").val($("#alternate").val() + suffix);
}
});
每次选择日期时,它都会将后缀添加到备用字段.
It adds the suffix to the alternate field each time you select a date.
这篇关于添加“st,nd,rd,th"到 jquery 日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文