秒表有多个显示器

时间:2014-10-27 18:15:05

标签: javascript mysql

您好,我目前正在使用javascript秒表(在网上找到)我做了一些更改但是到了这一点并且不确定如何继续,我想要一个秒表运行,但它显示多次(取决于有多少用户在mysql表中)我设法让它一次运行多个但它总是崩溃我的浏览器所以我假设我这样做的方式不正确? 我的javascript是

	var flagclock = 0;
	var flagstop = 0;
	var stoptime = 0;
	var splitcounter = 0;
	var currenttime;
	var splitdate = '';
	var output;
	var output1;
	var clock;
	
	function startstop()
		{
		
		var startstop = document.getElementById('startstopbutton');
		
	
		var startdate = new Date();
		var starttime = startdate.getTime();
		if(flagclock==0)
			{
			startstop.value = 'Stop';
			flagclock = 1;
			counter(starttime);
			}
		else
			{
			startstop.value = 'Start';
			flagclock = 0;
			flagstop = 1;
			splitdate = '';
			}
		}
		

	function counter(starttime)
		{
		output = document.getElementById('output');
		output1 = document.getElementById('output1');
		clock = document.getElementById('clock');
		
		
		currenttime = new Date();
		var timediff = currenttime.getTime() - starttime;
		if(flagstop == 1)
			{
			timediff = timediff + stoptime
			}
		if(flagclock == 1)
			{
			clock.value = formattime(timediff,'');
			refresh = setTimeout('counter(' + starttime + ');',10);
			}
		else
			{
			window.clearTimeout(refresh);
			stoptime = timediff;
			}
		
		}

	function formattime(rawtime,roundtype)
		{
		if(roundtype == 'round')
			{
			var ddds = Math.round(rawtime/1) + '';
			}
		else
			{
			var ddds = Math.floor(rawtime/1) + '';
			}
		if(roundtype == 'round')
			{
			var dds = Math.round(rawtime/10) + '';
			}
		else
			{
			var dds = Math.floor(rawtime/10) + '';
			}
		if(roundtype == 'round')
			{
			var ds = Math.round(rawtime/100) + '';
			}
		else
			{
			var ds = Math.floor(rawtime/100) + '';
			}
		var sec = Math.floor(rawtime/1000);
		var min = Math.floor(rawtime/60000);
		ds = ds.charAt(ds.length - 1);
		dds = dds.charAt(dds.length - 1);
		ddds = ddds.charAt(ddds.length - 1);
		if(min >= 60)
			{
			startstop();
			}
		sec = sec - 60 * min + '';
		if(sec.charAt(sec.length - 2) != '')
			{
			sec = sec.charAt(sec.length - 2) + sec.charAt(sec.length - 1);
			}
		else
			{
			sec = 0 + sec.charAt(sec.length - 1);
			}
		min = min + '';
		if(min.charAt(min.length - 2) != '')
			{
			min = min.charAt(min.length - 2)+min.charAt(min.length - 1);
			}
		else
			{
			min = 0 + min.charAt(min.length - 1);
			}
		return min + ':' + sec + ':' + ds + dds + ddds;
		}

	function resetclock()
		{
		flagstop = 0;
		stoptime = 0;
		splitdate = '';
		window.clearTimeout(refresh);
		output.value = '';
		output1.value = '';
		splitcounter = 0;
		if(flagclock == 1)
			{
			var resetdate = new Date();
			var resettime = resetdate.getTime();
			counter(resettime);
			}
		else
			{
			clock.value = "00:00:000";  
			}
		}
		

	function splittime()
		{
		if(flagclock == 1)
			{
			if(splitdate != '')
				{
				var splitold = splitdate.split(':');

				var splitnow = clock.value.split(':');
				
				var numbers = new Array();
				var i = 0
				for(i;i<splitold.length;i++)
					{
					numbers[i] = new Array();
					numbers[i][0] = splitold[i]*1;
					numbers[i][1] = splitnow[i]*1;
					}
				if(numbers[1][1] < numbers[1][0])
					{
					numbers[1][1] += 60;
					numbers[0][1] -= 1;
					}
				if(numbers[2][1] < numbers[2][0])
					{
					numbers[2][1] += 10;
					numbers[1][1] -= 1;
					}
				var mzeros = (numbers[0][1] - numbers[0][0]) < 10?'0':'';
				var szeros = (numbers[1][1] - numbers[1][0]) < 10?'0':'';
				output1.value += '\t+' + mzeros + (numbers[0][1] - numbers[0][0]) + ':' + szeros + (numbers[1][1] - numbers[1][0]) + ':' + (numbers[2][1] - numbers[2][0]) + '\n';
				}
			
			splitdate = clock.value;
			output.value = (++splitcounter) + '. ' + clock.value + '\n';
			
			}
		}
		
	<input id="clock" name="clock" type="text" value="00:00.000" style="text-align: center;" readonly>
	<input id="clock" name="clock" type="text" value="00:00.000" style="text-align: center;" readonly><br>
	
	<input id="startstopbutton" type="button" value="Start" onClick="startstop();"><br>
	<input id="splitbutton" type="button" value="Split time" onClick="splittime();"><br>
	<input id="resetbutton" type="button" value="Reset" onClick="resetclock();"><br>
	
	<input id="output" type="text" style="text-align: center;" readonly><input id="output" type="text" style="text-align: center;" readonly><br>
	
	<textarea id="output1" style="height: 20%;"></textarea><textarea id="output1" style="height: 20%;"></textarea>

因此,当按下开始按钮时,我希望它显示两个秒表,而不仅仅是一个,分段时间相同。我必须使用id(或类似的东西),因为当脚本放入我的编码时,它将从我的数据库中提供,因此对于多个用户,id将是相同的

0 个答案:

没有答案