<body onload="timer()">
<style type="text/css">
#time{
font-size:50pt;
}
#body
{
background-color:#F3F3F3;
}
</style>
<script type="text/javascript">
var digiclock = document.getElementById("<%= HiddenFieldMinutes.ClientID %>").value;
i = 0;
function timer() {
var digiformat = "";
if (i > 3599) {
var H = Math.floor(i / 3600);
}
else {
var H = 0;
}
var M = i - (H * 3600)
if (M > 59) {
M = Math.floor(M / 60)
}
else {
M = 0
}
var S = i - (M * 60)
if (H < 10) {
H = "0" + H;
}
if (M < 10) {
M = "0" + M;
}
if (S < 10) {
S = "0" + S;
}
document.getElementById('time').innerHTML = H + ":" + M + ":" + S;
setTimeout('timer()', 1000);
i++;
}
</script>
<table style="background-color:#F3F3F3;">
<tr>
<td><div><center><p style="font-family:Calibri;font-size:1.8em;color:#104E8B;">Total Elapsed Time</p> </center></div>
</td></tr>
<tr>
<td><div id="time"><center>90</center></div>
</td></tr>
<tr>
<td>
<center>
<form id="Form1" runat="server">
<asp:HiddenField ID="HiddenFieldMinutes" runat="server" Value="" />
<asp:Button ID="btnStop" runat="server" Text="Stop"
style="width:150px;height:30px;font-weight:bold;background-color:#104E8B;color:White;border:1px solid"
onclick="btnStop_Click" /></form></center>
<input id="HiddenTaskname" type="hidden" value="123" runat="server" />
</td></tr>
</table>
正如您在上面看到的,我试图创建一个从用户提供的指定时间开始的时钟。我将开始时间段存储在隐藏字段中。此页面的此页面加载背后的代码如下:-
protected void Page_Load(object sender, EventArgs e)
{
HiddenFieldMinutes.Value = null;
if (! IsPostBack)
{
//Checking for any query string
if (Request["Code"] != null)
{
_elapsedNonProdTimeEntryID =Convert.ToInt32 (Request["Code"].ToString());
_starttime = _nonProduction.GetStartTimeOfActiveTImeEntryID(_elapsedNonProdTimeEntryID);
TimeSpan elapsedtimespan = System.DateTime.Now.Subtract(_starttime);
string hh = elapsedtimespan.Hours.ToString();
string mm = elapsedtimespan.Minutes.ToString();
string ss = elapsedtimespan.Seconds.ToString();
_differenceOfTimeSpan = hh + ":" + mm + ":" + ss;
HiddenFieldMinutes.Value = _differenceOfTimeSpan;
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CloCkTImer", "javascript:timer(); ", true);
}
}
}
但是当我调试时,我在这条线上遇到错误。var digiclock = document.getElementById("<%= HiddenFieldMinutes.ClientID %>").value;
请帮助我改进此网页并完全满足我的要求。