简体   繁体   中英

Indicating the current date in date picker of a form in html 5

如何使用以下代码在html 5表单中将当前日期指示为占位符。

Date: <input type="date" placeholder="mm/dd/yyyy" name="date" />

To set the date inputs value to the current date, you can do something like this:

var d = new Date(),
    s = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate()

document.getElementsByName('date')[0].value = s;

FIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM