我想在輸入字段中顯示當前時間。我已經使用ID local-time
。但在輸入字段中,當前時間未顯示。如何使用jQuery設置輸入字段的值
Current Time : <input type="text" id = "local-time" value= ""/>
<script>
setInterval(function() {
var local = new Date();
var localdatetime = local.getHours() + ":" + pad(local.getMinutes()) + ":" +
pad(local.getSeconds());
$('#local-time').html(localdatetime);
}, 1000);
function pad(t) {
var st = "" + t;
while (st.length < 2)
st = "0" + st;
return st;
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>