数字の前に「0」を 1 文字追加するオプションはありますか?
例: 1、2、3、4、5、6、7、8、9
になる: 01、02、03、04、05、06、07、08、09
数字の前に「0」を 1 文字追加するオプションはありますか?
例: 1、2、3、4、5、6、7、8、9
になる: 01、02、03、04、05、06、07、08、09
作業例: http://jsfiddle.net/Gajotres/EHNab/
$(document).ready(function () {
$('#datepicker').datepicker({
beforeShowDay: function (date) {
var dayOfMonth = date.getDate();
if (dayOfMonth >= 1 && dayOfMonth <= 9) {
return [true, 'ui-change-format', ''];
}
return [true, '', ''];
}
});
});
.ui-change-format a::before {
content: "0";
}
には事前定義されたオプションはないと思いますUI Datepicker
。このためのカスタム コードを記述する必要があります。
beforeShow
とonChangeMonthYear
イベントのサンプルコードをいくつか書いて、これを試してください:
$('#picker').datepicker({
beforeShow: function (txt, inst) {
setTimeout(function(){
$("#ui-datepicker-div").find('table tr td[data-handler="selectDay"] > a').each(function(){
if($(this).text().trim().length < 2){
$(this).text("0" + $(this).text())
}
});
}, 100);
},
onChangeMonthYear: function (year, month, inst) {
setTimeout(function(){
$("#ui-datepicker-div").find('table tr td[data-handler="selectDay"] > a').each(function(){
if($(this).text().trim().length < 2){
$(this).text("0" + $(this).text())
}
});
}, 100);
}
});