日常小记

js获取当前时间并赋给input表单

<input name="tijiaoshijian" value="" type="text"  id="mytime"  />
  <script>

function t(){
var now= new Date();
var y=now.getFullYear();
var mon=now.getMonth()+1;
var d=now.getDate();
var h=now.getHours();
var m=now.getMinutes();
var s=now.getSeconds();
if (h>=0 && h <=12)
var ho=" AM";
if (h>12 && h<24)
var ho=" PM";
var tt=y+"-"+mon+"-"+d+" "+h+":"+m+":"+s+ho;
document.getElementById("mytime").value=tt;
}
setInterval('t()',500);
</script>

回复

This is just a placeholder img.