4

我需要在 jQuery UI 日期选择器中显示前导零:

例如,

1 2 3 4 5 6 7 8 9 10->01 02 03 04 05 06 07 08 09 10

与此类似的问题:

http://forum.jquery.com/topic/displaying-leading-zero-for-day-numbers-of-datepicker

也许有人确实有解决方法?

4

4 回答 4

4

这是我的黑客解决方案。有用!:)

我们可以使用 CSS 和 JavaScript 的组合。我们可以在我们的方法中利用一个datepicker事件。beforeShowDay

CSS:

.ui-datepicker-calendar td.zero a:before {
    content: "0";
}​

JavaScript:

$("input").datepicker({
    beforeShowDay : function(date) {
        var day = date.getDate();
        return [true, (day < 10 ? "zero" : "")];
    }
});

演示:http: //jsfiddle.net/vZ7wm/

于 2012-05-29T12:40:52.973 回答
2

为此,您需要破解 daterpicker 插件。

获取_generateHTML方法。后

for (var dow = 0; dow < 7; dow++) {// 创建日期选择器天数

放置此代码

var customgetDate = printDate.getDate();
if(customgetDate<=9){
 customgetDate= '0'+ customgetDate;
}

然后找到这个“ printDate.getDate() + '</a>') ”现在替换它;

 customgetDate + '</a>') 

就这样.....

于 2012-05-29T12:57:41.690 回答
0

显示月份数字的前导零?也许是这样的:

<script type="javascript/text">
$(document).ready(function() {
    $(".cssselector").datepicker({ dateFormat: 'dd/mm/yy' });
});
</script>
于 2012-05-29T12:40:47.913 回答
0

过时的接受答案。应该:

$('#fromDate, #toDate').datepicker({
    dateFormat : 'yymmdd'
});
于 2014-04-07T05:14:12.707 回答