⽇期类型的input元素设置默认值为当天
html5的form元素对⽇期时间有丰富的⽀持
<input type="date">
<input type="time">
<input type="datetime">
浏览器json格式化<input type="month">
<input type="week">
<input type="datetime-local">
问题是,你使⽤了它们后,发现⽇期并不是默认在当天的(没有默认任何⽇期),⽽且el.value=new Date()也不⾏,只⽀持yyyy-MM-ddTHH:mm:ss.SSS(或其部分)这种形式的的字符串:
From the :
A string representing a date.
Value: A valid full-date as defined in , with the additional qualification that the year component is four or more digits representing
a number greater than 0.
js默认是没有⽇期格式化函数的,除⾮你打算:
引⼊⼀个js的⽇期库
⾃⼰写⼀个简单的⽇期扩展类(⾃⼰考虑每⽉天数的不同,闰年等等问题,以实现⽇期的增减)
⽤后台语⾔直接在value的位置格式化输出,如<?=date('Y-m-d').'T'.date('H:i') ?>
在到了⼀个简单的⽤法,在此,使⽤:
有意思的是,我⽤jQuery的选择器居然不能使⽤这个属性(设置了后⽆效)
此外,这些新玩意你只能在有限场景使⽤,⽣产环境是没意义的,浏览器⽀持太⽔了。