SignalR实时秒表 - MVC ASP.NET

时间:2015-09-29 10:59:42

标签: model-view-controller timer signalr real-time stopwatch

我在ASP.NET MVC项目中使用javascript创建了秒表,我想使用带有淘汰赛的SignalR或任何其他可以向所有连接的客户端查看秒表的技术。 这是代码:

    <html>
<head>
<style>
#output{
width:120px;
height:25px;
background-color:#ccc;
border: 1px solid #999;}
</style>

<script>
var time = 0; 
var running = 0;

function startPause(){
if(running == 0){
running = 1;
increament();
document.getElementById("startPause").innerHTML = "Pause";
}
else{
running = 0;
document.getElementById("startPause").innerHTML = "Resume";
}
}

function reset(){
running = 0;
time = 0;
document.getElementById("startPause").innerHTML = "Start";
document.getElementById("output").innerHTML = "00:00:00";

}

function increament(){
if(running == 1){
setTimeout(function(){
time++;
var mins = Math.floor(time/10/60);`<html>
<head>
<style>
#output{
width:120px;
height:25px;
background-color:#ccc;
border: 1px solid #999;}
</style>

<script>
var time = 0; 
var running = 0;

function startPause(){
if(running == 0){
running = 1;
increament();
document.getElementById("startPause").innerHTML = "Pause";
}
else{
running = 0;
document.getElementById("startPause").innerHTML = "Resume";
}
}

function reset(){
running = 0;
time = 0;
document.getElementById("startPause").innerHTML = "Start";
document.getElementById("output").innerHTML = "00:00:00";

}

function increament(){
if(running == 1){
setTimeout(function(){
time++;
var mins = Math.floor(time/10/60);
var secs = Math.floor(time/10%60);
var tenths = time % 10;
if(mins<10){mins= "0" + mins;}
if(secs<10){secs= "0" + secs;}

document.getElementById("output").innerHTML = mins + ":" + secs + ":" + "0" + tenths;
increament();
}, 100);}
}


</script>

</head>
<body>
<p id="output">00:00:00</p>
<div id="controls">
<button id="startPause" onclick="startPause()">Start</button>
<button id="startPause" onclick="reset()">Reset</button>


</div>

</body>
</html>`
var secs = Math.floor(time/10%60);
var tenths = time % 10;
if(mins<10){mins= "0" + mins;}
if(secs<10){secs= "0" + secs;}

document.getElementById("output").innerHTML = mins + ":" + secs + ":" + "0" + tenths;
increament();
}, 100);}
}


</script>

</head>
<body>
<p id="output">00:00:00</p>
<div id="controls">
<button id="startPause" onclick="startPause()">Start</button>
<button id="startPause" onclick="reset()">Reset</button>


</div>

</body>
</html>

我已经应用了很多signalR项目,但他们都向所有客户发布(推送)数据,我认为这无法帮助我向所有客户查看秒表。

0 个答案:

没有答案