基本上,我想创建一个运行中的自动收报机,它会持续(每1-15秒,无关紧要)更新我们公司根据设定的等式(例如每分钟25美分)节省的能源总量。它将基于实际的时钟/日历时间,而不仅仅是访问者访问页面的时间。
我希望使用javascript (或jQuery)来做这件事,但我对这两种语言都是新手,经验很少。
谢谢!
发布于 2012-08-08 23:17:04
进行计算并定期更新它们并不是很难。你需要使用JavaScript Date Object来获得你的时间。您还可以使用setInterval函数来执行定期更新。
发布于 2012-08-08 23:19:08
我不知道您对javascript的了解程度,但是有两个名为window.setInterval和window.clearInterval的函数可以用来在特定的时间间隔生成事件。
发布于 2012-08-08 23:22:39
你可以使用window.setInterval(函数,以毫秒为单位的时间);基本上:
var money_value=0.25; //25 cents
var timing=15; //15 seconds
var global_calculator=0; //start time could be brought in by php or whatever
window.setInterval("calculate()",timing*1000); //timing*1000 milliseconds
// means 15 seconds
function calculate(){
global_calculator+=15; //add the passed seconds to the total of seconds
total=global_calculator*money_value; //calculate the total savings
update_clock(); //your function that updates the values some where to show them;
}应该就是这样了。
https://stackoverflow.com/questions/11867658
复制相似问题