admin管理员组文章数量:1355540
Hoe to set up a value, to input type = time , set in html using value attribute value.
I have tried:
var tm = new Date();
var in= "<input type='time' name='time' id='tm' value='" + tm + "'/>";
it does not work
Hoe to set up a value, to input type = time , set in html using value attribute value.
I have tried:
var tm = new Date();
var in= "<input type='time' name='time' id='tm' value='" + tm + "'/>";
it does not work
Share Improve this question edited May 23, 2013 at 16:48 BoltClock 725k165 gold badges1.4k silver badges1.4k bronze badges asked May 23, 2013 at 16:08 Emmanuel NEmmanuel N 7,4472 gold badges29 silver badges36 bronze badges 3- javascript, I'm assuming? What makes you think you can simply stuff a JS OBJECT into a string that happens to contain an html input definition? – Marc B Commented May 23, 2013 at 16:10
-
what is a proper way to do it? That an easy way to convert an object to string, will automatically call
toString()
for that particular object. – Emmanuel N Commented May 23, 2013 at 16:14 -
yes, but how is the JS engine to know how to format that stringified date?
yyyy-mm-dd
?dd-mm-yy
? unix timestamp? read up on the JS Date object ... – Marc B Commented May 23, 2013 at 16:15
1 Answer
Reset to default 6Use the valueAsDate attribute to convert between a Date
object and an input element’s value.
> var elem = document.createElement('input');
> elem.type = 'time';
> elem.valueAsDate = new Date(1970, 1, 1, 7, 34);
> elem.value
"12:34"
本文标签: javascriptInput time type time setting valueStack Overflow
版权声明:本文标题:javascript - Input time [type= time] setting value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744047279a2581762.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论