简体   繁体   English

如何从输入时间html标记获取第二个值到JavaScript变量

[英]How to get second value from input time html tag to JavaScript variable

s1 variable is not getting seconds value enter code here s1变量没有获得秒值,请在此处输入代码

 function fun() { time=document.getElementById("time").value; h1=time[0]; h2=time[1]; m1=time[3]; m2=time[4]; s1=time[6];// Not Working document.getElementById("print").value=h1+""+h2+""+":"+m1+""+m2+":"+s1; } setInterval(fun,1000); 
 <p>Time:<p> <input type="time" id="time" name="time" step="1"></input><br> <input type="text" id="print"></input> 

Is this what you want? 这是你想要的吗?

 function fun() { time=document.getElementById("time").value; h1=time[0]; h2=time[1]; m1=time[3]; m2=time[4]; s1=time[6]; s2=time[7]; document.getElementById("print").value = h1+""+h2+""+":"+m1+""+m2+":"+s1+""+s2; } 
 <p>Time:</p><input type="time" id="time" name="time" step="1"></input><br> <input type="text" id="print"></input> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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