PHP网站中的多个秒表需要很多帮助 [英] multiple stopwatch in a php site much help needed

查看:67
本文介绍了PHP网站中的多个秒表需要很多帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在php站点中实现多次停止监视以显示技术人员解决问题所花费的不同时间.


在我的网站上,有工作要分配给技术人员完成,我想知道技术人员解决问题所需的时间.我借助Java脚本实现了一个简单的秒表,并且一直工作到我们停留在页面上但是当我们转到另一个页面时,该页面将停止.
下一个问题是,当我尝试在同一页面中使用多个秒表实现时,只有一个正在工作.
很抱歉发生严重错误,因为我的英语是一周.

代码在这里



how can implement a multiple stop watch in a php site for displaying different time consume by the technicians to resolve the problem.


in my site there are work assign for completion to technician where i want to know about how much time taken by the technician in solving the problem.i implement a simple stop watch with the help of java script and is working untill when we stay on page but when we go another page then it is stopped.
and next problem is that when i try it to multiple stopwatch implement in the same page then only one is working.
sorry for gramitical error becoz my english is week.

the code is here



var swCycleTime=50; //run cycle every 50ms?

// Functional Code

var sw,swObj,swct,swnow,swcycle; //create some variables, we'll figure out what they are soon
var swObjAry=new Array(); //and i assume that for every stopwatch on the page an object is created and this is the container array

function swStart(id,ud){ //ok so you click the button which would onclick="swstart($divname,+);" the plus is for count upwards, you can - it
swObj=document.getElementById(id); //so the swobj var is your actual div by the look of it
swct=swObj.innerHTML.split(':'); //and it splits the time into minutes, seconds, milliseconds into an array
swnow=new Date(); //this is the time the button got clicked
swObj.now=swnow.getTime(); //and it fires that variable into swobj's now value
swObj.reset=swObj.innerHTML; //it takes a note of whats in the div so that when you reset, it puts the initial value back in
swObj.ud=ud; //the stopwatch object is told wether to count up or down
if (!isNaN(swObj.innerHTML)){ //if the initial value turns out to be a string,
swObj.time=parseInt(swObj.innerHTML); //parse it to an int
}
else if (swct.length==4){ //otherwise if our split is 4 long, for hours!
swObj.time=(swct[0]*1000*60)+(swct[1]*1000*60)+(swct[2]*1000)+parseInt(swct[3]); //the stopwatches time so far is mins + secs +ms (total being in ms)
}
else if (swct.length==3){ //otherwise if our split is 3 long
swObj.time=(swct[0]*1000*60)+(swct[1]*1000)+parseInt(swct[2]); //the stopwatches time so far is mins + secs +ms (total being in ms)
}
else if (swct.length==2){ //or if its just seconds and milliseconds
swObj.time=(swct[0]*1000)+parseInt(swct[1]);
}
else if (swct.length==1){ //or just milliseconds
swObj.time=parseInt(swct[1]);
}
if (!swObj.time){ //if it has only just started at 0
swObj.time=1; //give it a millisecond to get it started
}
if (!swObj.c){ //if there isnt a c value (whatever c is :-P )
swObj.c=ud; //then make it + or -, whatever ud was
swObjAry[swObjAry.length]=swObj; //i dont get this - make the number of stopwatches = swobj, the div? :-s
}
}

function swStop(id){ //anyway, so if you click the stop button (onclick="swstop($divname)"),
swObj=document.getElementById(id); //get the stopwatch div name
if (!swObj.time){ return; } //if there is no time variable, its already stopped. coolio.
swObj.time=null; //get rid of the time value
sw=new Date().getTime(); //this next bit will have to do with when you resume i suppose
swObj.cycle+=(sw-swcycle);
if (swObj.ud=='-'){
swObj.cycle-=(sw-swcycle);
if (swObj.cycle<0){ swObj.cycle=0; }
}
swObj.innerHTML=(parseInt(swObj.cycle/1000/60/60)%60)+':'+(parseInt(swObj.cycle/1000/60)%60)+':'+((parseInt((swObj.cycle)/1000)%60)+':'+(swObj.cycle%1000));
//display the time you stopped on, i added an extra bit here hor the hour
}

function swCycle(){ //and this will be the running cylce then
swcycle=new Date().getTime();
for (sw0=0;sw0<swobjary.length;sw0++){>
if (swObjAry[sw0].time){
swObjAry[sw0].cycle=swObjAry[sw0].time+(swcycle-swObjAry[sw0].now);
if (swObjAry[sw0].ud=='-'){
swObjAry[sw0].cycle=swObjAry[sw0].time-(swcycle-swObjAry[sw0].now);
if (swObjAry[sw0].cycle<0){ swObjAry[sw0].cycle=0; swObjAry[sw0].time=0; }
}

swObjAry[sw0].innerHTML=(parseInt(swObjAry[sw0].cycle/1000/60/60)%60)+':'+(parseInt(swObjAry[sw0].cycle/1000/60)%60)+':'+((parseInt((swObjAry[sw0].cycle)/1000)%60)+':'+(swObjAry[sw0].cycle%1000)); //added an hour bit here too
}
}
}

function swReset(id,dt){
swObj=document.getElementById(id);
swObj.innerHTML=swObj.reset;
swObj.time=null;
}

setInterval('swCycle()',swCycleTime);





<input type="button" value="Start"  önclick="swStart('beg2','+');">
<input type="button" value="Stop"  önclick="swStop('beg2');">
<input type="button" value="Reset"  önclick="swReset('beg2');">
<div id="beg2">0:00:00:000</div>

推荐答案

divname,+);加号表示向上计数,您可以-它 swObj = 文档 .getElementById(id); // 因此,swobj var从外观上来说就是您的实际div swct = swObj.innerHTML.split(' :'); // ,它将时间分为分钟,秒,毫秒分成一个数组 swnow = 日期(); // 这是单击按钮的时间 swObj.now = swnow.getTime(); // ,它会将变量触发为swobj的现在值 swObj.reset = swObj.innerHTML; // 它会记录div中的内容,以便您重置时将初始值放回 swObj.ud = ud; // 秒表对象被告知是否向上或向下计数 如果(!isNaN(swObj.innerHTML)){// 如果初始值是字符串,则 swObj.time = parseInt (swObj.innerHTML); // 将其解析为整数 } 其他 如果(swct.length == 4 ){// 否则,如果我们的拆分时间为4个小时,则持续数小时! swObj.time =(swct [ 0 ] * 1000 * 60)+(swct [ 1 ] * 1000 * 60)+(swct [ 2 ] * 1000)+ parseInt(swct [ 3 ]); // 到目前为止,秒表时间为分钟+秒+毫秒(总计以毫秒为单位) } 其他 如果(swct.length == 3 ){// 否则,如果我们的拆分为3个长 swObj.time =(swct [ 0 ] * 1000 * 60)+(swct [ 1 ] * 1000 )+ parseInt(swct [ 2 ]); // 到目前为止,秒表时间为分钟+秒+毫秒(总计以毫秒为单位) } 其他 如果(swct.length == 2 ){// ,或者仅需几秒钟和毫秒 swObj.time =(swct [ 0 ] * 1000)+ parseInt(swct [ 1 ]); } 其他 如果(swct.length == 1 ){// 或仅毫秒 swObj.time = parseInt (swct [ 1 ]); } 如果(!swObj.time){// 如果它刚从0开始 swObj.time = 1 ; // 给它一毫秒以使其开始使用 } 如果(!swObj.c){// is ac值(无论c是:-P) swObj.c = ud; // 然后将其设置为+或-,无论ud是什么 swObjAry [swObjAry.length] = swObj; // 我不明白这一点-使秒表的数量= swobj,div? :-s } } 功能 swStop(id){// 无论如何,如果您单击停止按钮(onclick ="swstop(
divname,+);" the plus is for count upwards, you can - it swObj=document.getElementById(id); //so the swobj var is your actual div by the look of it swct=swObj.innerHTML.split(':'); //and it splits the time into minutes, seconds, milliseconds into an array swnow=new Date(); //this is the time the button got clicked swObj.now=swnow.getTime(); //and it fires that variable into swobj's now value swObj.reset=swObj.innerHTML; //it takes a note of whats in the div so that when you reset, it puts the initial value back in swObj.ud=ud; //the stopwatch object is told wether to count up or down if (!isNaN(swObj.innerHTML)){ //if the initial value turns out to be a string, swObj.time=parseInt(swObj.innerHTML); //parse it to an int } else if (swct.length==4){ //otherwise if our split is 4 long, for hours! swObj.time=(swct[0]*1000*60)+(swct[1]*1000*60)+(swct[2]*1000)+parseInt(swct[3]); //the stopwatches time so far is mins + secs +ms (total being in ms) } else if (swct.length==3){ //otherwise if our split is 3 long swObj.time=(swct[0]*1000*60)+(swct[1]*1000)+parseInt(swct[2]); //the stopwatches time so far is mins + secs +ms (total being in ms) } else if (swct.length==2){ //or if its just seconds and milliseconds swObj.time=(swct[0]*1000)+parseInt(swct[1]); } else if (swct.length==1){ //or just milliseconds swObj.time=parseInt(swct[1]); } if (!swObj.time){ //if it has only just started at 0 swObj.time=1; //give it a millisecond to get it started } if (!swObj.c){ //if there isnt a c value (whatever c is :-P ) swObj.c=ud; //then make it + or -, whatever ud was swObjAry[swObjAry.length]=swObj; //i dont get this - make the number of stopwatches = swobj, the div? :-s } } function swStop(id){ //anyway, so if you click the stop button (onclick="swstop(


divname)"), swObj = 文档 .getElementById(id); // 获取秒表div名称 如果(!swObj.time){返回; } // 如果没有时间变量,则该变量已停止. coolio. swObj.time = // 摆脱时间值 sw = 日期().getTime(); // 我想,这下一点与您恢复简历有关 swObj.cycle + =(sw-swcycle); 如果(swObj.ud == ' -'){ swObj.cycle-=(sw-swcycle); 如果(swObj.cycle< 0){swObj.cycle = 0 ; } } swObj.innerHTML =( parseInt (swObj.cycle/1000/60/60)%60)+ ' :' +( parseInt (swObj.cycle/1000/60)%60)+ ' :' +(( parseInt ((swObj.cycle )/1000)%60)+ ' :' +(swObj.cycle%1000));; // 显示您停下来的时间,我在整点钟时都在这里加了 } 功能 swCycle(){// 这将是然后运行cylce swcycle = 日期().getTime(); for (sw0 = 0 ; sw0< swobjary.length; sw0 ++){> 如果(swObjAry [sw0] .time){ swObjAry [sw0] .cycle = swObjAry [sw0] .time +(swcycle-swObjAry [sw0] .now); 如果(swObjAry [sw0] .ud == ' - '){ swObjAry [sw0] .cycle = swObjAry [sw0] .time-(swcycle-swObjAry [sw0] .now); 如果(swObjAry [sw0] .cycle< 0){swObjAry [sw0] .cycle = 0 ; swObjAry [sw0] .time = 0 ; } } swObjAry [sw0] .innerHTML =( parseInt (swObjAry [sw0] .cycle/1000/60/60)%60)+ ' :' +( parseInt (swObjAry [sw0] .cycle/1000/60 )%60)+ ' :' +(( parseInt (((swObjAry [sw0] .cycle)/1000)%60)+ ' :' +(swObjAry [sw0] .cycle%1000)); // 在这里也增加了一个小时的时间 } } } 函数 swReset(id,dt){ swObj = 文档 .getElementById(id); swObj.innerHTML = swObj.reset; swObj.time = ; } setInterval(' swCycle()',swCycleTime);
divname)"), swObj=document.getElementById(id); //get the stopwatch div name if (!swObj.time){ return; } //if there is no time variable, its already stopped. coolio. swObj.time=null; //get rid of the time value sw=new Date().getTime(); //this next bit will have to do with when you resume i suppose swObj.cycle+=(sw-swcycle); if (swObj.ud=='-'){ swObj.cycle-=(sw-swcycle); if (swObj.cycle<0){ swObj.cycle=0; } } swObj.innerHTML=(parseInt(swObj.cycle/1000/60/60)%60)+':'+(parseInt(swObj.cycle/1000/60)%60)+':'+((parseInt((swObj.cycle)/1000)%60)+':'+(swObj.cycle%1000)); //display the time you stopped on, i added an extra bit here hor the hour } function swCycle(){ //and this will be the running cylce then swcycle=new Date().getTime(); for (sw0=0;sw0<swobjary.length;sw0++){> if (swObjAry[sw0].time){ swObjAry[sw0].cycle=swObjAry[sw0].time+(swcycle-swObjAry[sw0].now); if (swObjAry[sw0].ud=='-'){ swObjAry[sw0].cycle=swObjAry[sw0].time-(swcycle-swObjAry[sw0].now); if (swObjAry[sw0].cycle<0){ swObjAry[sw0].cycle=0; swObjAry[sw0].time=0; } } swObjAry[sw0].innerHTML=(parseInt(swObjAry[sw0].cycle/1000/60/60)%60)+':'+(parseInt(swObjAry[sw0].cycle/1000/60)%60)+':'+((parseInt((swObjAry[sw0].cycle)/1000)%60)+':'+(swObjAry[sw0].cycle%1000)); //added an hour bit here too } } } function swReset(id,dt){ swObj=document.getElementById(id); swObj.innerHTML=swObj.reset; swObj.time=null; } setInterval('swCycle()',swCycleTime);





<input type="button" value="Start"  önclick="swStart('beg2','+');">
<input type="button" value="Stop"  önclick="swStop('beg2');">
<input type="button" value="Reset"  önclick="swReset('beg2');">
<div id="beg2">0:00:00:000</div>


这些变量sw,swObj,swct,swnow,swcycle是您的问题.

您只有一个实例.但是所有计时器都需要它们.创建新的计时器时,您将覆盖这些变量的状态并杀死以前的计时器.

创建新计时器时,需要确保该计时器使用的所有变量对于该计时器都是唯一的.
These variables sw,swObj,swct,swnow,swcycle are your problem.

You only have one instance of them. But they are required for all timers. When you create a new timer you''re over writing the state of these variables and killing the previous timer.

When you create a new timer, you need to make sure that all the variables used by that timer are unique to that timer.


这篇关于PHP网站中的多个秒表需要很多帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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