Now the HTML5 input tag supports type= "date" to display a calendar control with dates, a simple line of code can display a calendar control, but sometimes it is necessary to give it a default date value, this time may need to use Val (), attr ("Value", "") And so on, it is possible that many people will not succeed, in fact, it is not the label does not support the method of assignment, but the value of the string when the format of the problem.
Solution: As soon as you say it, we usually use the new date (). GetMonth () new Date (). GetDate () method when the date is less than 10, the default display is 1,2,3,4,5,6,7,8,9 So the date format could be 2013-9-5. The date format supported in input type= "date" is 2013-09-05, and this value is passed to the input tag to display the value of the date normally, so here is a judgment, if the number of months or the number of days is less than 10, it is necessary to add the number 0 before it to form a string , so that it can be assigned to the normal display.
varnow =NewDate (); Alert (now.getdate ()+'-'+now.getmonth ()); //format day, if less than 9, the front complement 0varDay = ("0"+ now.getdate ()). Slice (-2); //format month, if less than 9, front 0varMonth = ("0"+ (Now.getmonth () +1). Slice (-2); //assemble the full date formatvarToday = Now.getfullyear () +"-"+ (Month) +"-"+(day); //Completion Assignment$('#createStartTime'). val (today);
Original address: 72640051
How to assign a value to input type= "date" tag in HTML (GO)