как добавить 0 код дням в календаре?

302
24 ноября 2016, 10:08

не работают 0 в от 1-9 в календаре тоесть все даты прдсвечиваются а вот все что от 1 до 9 нет я так понимаю нужен ноль но как его добавить в код что бы работало

("0" + curr_date).slice(-2)

я знаю есть такая функция, но она не работает

	var active_dates = ["11/12/2016",  "13/12/2016", "01/01/2017", "15/01/2017", "16/01/2017"]; 
	 
	$("#datepicker").datepicker({ 
		 format: "dd/mm/yyyy",  
		  
		 todayHighlight: true, 
		 maxViewMode: 0, 
    beforeShowMonth: 1, 
  
 
		 beforeShowDay: function(date){ 
			 var d = date; 
			 var curr_date = d.getDate(); 
			 var curr_month = d.getMonth() + 1; //Months are zero based 
			 var curr_year = d.getFullYear() ; 
            if(curr_month<10)curr_month = "0"+curr_month; 
                if(curr_date<10)curr_date = "0"+curr_month; 
			 var formattedDate = curr_date + "/" + curr_month + "/" + curr_year 
 
			   if ($.inArray(formattedDate, active_dates) != -1){ 
				   return { 
					  classes: 'booked ' 
				   }; 
			   } 
			  return; 
		  } 
	  });
.booked{ 
	background: #F00!important;  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet"/> 
<link href="http://bsdp-assets.blackcherry.us/1.3.0/datepicker3.min.css" rel="stylesheet"/> 
<script src="http://bsdp-assets.blackcherry.us/1.3.0/bootstrap-datepicker.min.js"></script> 
 
<div id="datepicker"></div> 
<input type="hidden" id="my_hidden_input">

Answer 1
function addLeadingZero (n) {
    return (n < 10) ? '0' + n : n;
}
Answer 2

const format = ( value, length ) =>  
  `${"0".repeat(length - value.toString().length)}${value}`; 
 
console.log(format(9, 2)); 
console.log(format(12, 2)); 
console.log(format(10, 3));

Тоже самое, но при помощи рекурсии -

const format = ( value, length ) =>  
  value.toString().length < length ? format( "0" + value.toString(), length ) : value; 
 
console.log(format(9, 2)); 
console.log(format(12, 2)); 
console.log(format(10, 3));

Answer 3

var active_dates = ["15/11/2016", "01/01/2017"]; 
 
$("#datepicker").datepicker({ 
		 format: "dd/mm/yyyy",  
 todayHighlight: true, 
		 maxViewMode: 0, 
    beforeShowMonth: 1, 
  beforeShowDay: function(date){ 
			 var d = date; 
			 var day = d.getDate()  ; 
       var curr_date = "0" + day; 
			 var month = d.getMonth() + 1; //Months are zero based 
       var curr_month = "0" + month; 
			 var curr_year = d.getFullYear() ; 
         if (curr_date == 00) { 
       curr_date = 10; 
       }        
       if (curr_date.length > 2){ 
       curr_date = (curr_date).slice(1); 
       } 
      
       if (curr_month == 00) { 
       curr_month = 12; 
       }        
       if (curr_month.length > 2){ 
       curr_month = (curr_month).slice(1); 
       } 
      
			 var formattedDate = curr_date + "/" + curr_month + "/" + curr_year 
        
			   if ($.inArray(formattedDate, active_dates) != -1){ 
				   return { 
					  classes: 'booked ' 
				   }; 
			   } 
			  return; 
		  } 
	  });
.booked{ 
	background: #F00!important;  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet"/> 
<link href="http://bsdp-assets.blackcherry.us/1.3.0/datepicker3.min.css" rel="stylesheet"/> 
<script src="http://bsdp-assets.blackcherry.us/1.3.0/bootstrap-datepicker.min.js"></script> 
 
<div id="datepicker"></div> 
<input type="hidden" id="my_hidden_input">

READ ALSO
Не отображается картинка в a.menu:visited в CSS

Не отображается картинка в a.menu:visited в CSS

При наведении, фокусе, visited, активации и псевдокселекторе link должно отображать рисунок. Visited не работает.

327
Как управлять градиентов в SVG через CSS?

Как управлять градиентов в SVG через CSS?

Мне нужно чтобы при наведении на блок, у SVG появлялся градиент. Как это реализовать?.

392
Альтернативы выпадающему списку [требует правки]

Альтернативы выпадающему списку [требует правки]

Какие есть альтернативы стандартному раскрывающемуся списку (селекту).

387