0

数字の前に「0」を 1 文字追加するオプションはありますか?

例: 1、2、3、4、5、6、7、8、9

になる: 01、02、03、04、05、06、07、08、09

ここに画像の説明を入力

4

3 に答える 3

3

作業例: http://jsfiddle.net/Gajotres/EHNab/

JavaScript:

$(document).ready(function () {
    $('#datepicker').datepicker({
        beforeShowDay: function (date) {
            var dayOfMonth = date.getDate();
            if (dayOfMonth >= 1 && dayOfMonth <= 9) {
                return [true, 'ui-change-format', ''];
            }
            return [true, '', ''];
        }
    });
});

CSS:

.ui-change-format a::before { 
  content: "0";
}
于 2014-06-10T11:06:39.913 に答える
1

には事前定義されたオプションはないと思いますUI Datepicker。このためのカスタム コードを記述する必要があります。

beforeShowonChangeMonthYearイベントのサンプルコードをいくつか書いて、これを試してください:

$('#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);
    }
});

実施例

于 2014-06-10T11:27:19.680 に答える