0
我有一個html頁面,需要存儲按鈕點擊數據庫時的時間。我有一個計算時間的JS函數。但不知怎麼的,html按鈕沒有保存這個值。這裏是代碼。如何將一個JS函數的輸出返回到一個HTML按鈕'id'
<html>
<head>
<script>
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
function checkMsec(j)
{
if ((j<100) && (j<10))
{
j="00" + j;
}
if ((j<100) && (j>10))
{
j="0" + j;
}
return j;
}
function timeCheck(stTime)
{
var currentTime=new Date();
var cDat = currentTime.getDate();
var cMon = currentTime.getMonth() + 1;
var cYear = currentTime.getFullYear();
var h = currentTime.getHours();
var m = currentTime.getMinutes();
var s = currentTime.getSeconds();
var ms = currentTime.getMilliseconds();
m = checkTime(m);
s = checkTime(s);
ms = checkTime(ms);
stTime = cDat+"-"+cMon+"-"+cYear+" "+h+":"+m+":"+s+":"+ms;
//alert(stTime); // this is displaying the time as an alert
return stTime; //Here I am expecting the id attribute of the button will have the stTime
}
</script>
</head>
<body>
<form name ="frm1" method ="POST" action="<% gait_url %>">
<p>Time 1: <input type="button" name=start1 value= "Start" id="start1" onClick ="timeCheck(this)">
<input type="button" name=stop1 id="stop1" value= "Stop" onClick ="timeCheck(this)"></p>
<p>Time 2: <input type="button" name=start2 value= "Start" id="start2" onClick ="timeCheck(this)">
<input type="button" name=stop2 id="stop2" value= "Stop" onClick ="timeCheck(this)"> </p>
<input type="submit" value="Back to Menu" name="Back to Menu">
</form>
</body>
</html>