How to assign a value to input type= "date" tag in HTML (GO)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.