请检查出来并做需要 [英] please check it out and do the need

查看:58
本文介绍了请检查出来并做需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Digitl clock</title>
<style type="text/css">
#time{
font-size:50pt;
}
</style>
</head>
<body  önload="timer()">

<script type="text/javascript" language=javascript>
//var digiclock = "00:00:00";
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;
    document.getElementById('lblTimer').innerHTML = H+":"+M+":"+S;
    setTimeout('timer()', 1000);
    i++;
}
</script>

<%--<asp:HiddenField ID="hidenfld" runat="server" />--%>
<asp:Label ID="lblTimer" runat="server" Font-Size="30px"    ></asp:Label>     
<input type=button ID="btnrefresh"  runat="server" value="refresh"/>

</body>
</html>


我尝试了所有方法,如何避免刷新计数器.


How can I avoid refresh of counter, I tried all the ways.

推荐答案

也许这样的方法可以为您提供帮助:

Maybe something like this will help you:

<body onload="timer()">
    <form id="form1" runat="server">
    <div>
        <asp:hiddenfield runat="server" id="timerValue" value="0" xmlns:asp="#unknown" />
        <script type="text/javascript" language="javascript">
            function timer() {
                var timerValue = document.getElementById("timerValue");
                var i = timerValue.value;
                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('lblTimer').innerHTML = H + ":" + M + ":" + S;
                setTimeout('timer()', 1000);
                i++;
                timerValue.value = i;
            }
        </script>
        <label id="lblTimer" style="font-size:30px"></label>     
        <asp:button runat="server" text="Refresh" xmlns:asp="#unknown" />
    </div>
    </form>
</body>


使用隐藏字段

1.从服务器(功能的第一行)中读取i

2. i++;之后,使用__doPostBack将值发布到服务器.

我认为每次刷新后i都不会闪烁.
Use hidden fields

1. Read i from Server (First line of your function)

2. after i++; , use __doPostBack to post the value to server.

I think after every refresh the i is not flashing.


这篇关于请检查出来并做需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆