<!DOCTYPE html>
<html>
<head>
<title>consultation</title>
<link rel="stylesheet" type="text/css" href="css/consultation.css">
<script type="text/javascript">
var date_1;
//setInterval( functionDate() , 999 );
function functionDate()
{
//alert( form_1.length );
date_1 = new Date();
date_1 = date_1.getHours() + ":" + date_1.getMinutes() + ":" + date_1.getSeconds();
form_1.date.value = "";
form_1.date.value = "date_1";
}
</script>
</head>
<body>
<form name="form_1" >
<div id="container">
<div id="header">
<img src="images/picture_1.png" id="image" width="60" height="60">
<p id="select_product_p">
Select product:
</p>
<input list="product" id="select_product">
<datalist id="product" >
<option>Tortilla</option>
<option>Masa</option>
</datalist>
<p id="product_amount_p">
Product amount:
</p>
<input type="number" id="product_amount" min="1">
<p id="unit_price_p">
Unit price:
</p>
<input type="number" id="unit_price" min="1" size="5">
<button type="button" id="add_product">Add Product</button>
<input type="text" name="hour" id="hour_id">
<!--
</div>
<div id="medium">
</div>
<div id="final">
</div>
</div>
-->
</form>
</body>
</html>
我尝试用setInterval构建一个时钟,然后把我们放在输入标签上,但我不知道为什么是错的。我知道我可以更改标签上的值。想想也许我可以使用.innerHTML。谢谢。
答案 0 :(得分:0)
我不确定我是否得到了你想要达到的目标,但是为了在输入字段中设置时间,你可以这样做:
var nowDate = new Date();
var timeString = nowDate.getHours() + ":" + nowDate.getMinutes() + ":" + nowDate.getSeconds();
document.getElementById("hour_id").value = timeString;