好的; 所以我设法让我的计数器工作(我猜它工作得很好;不确定它是否有效或其他)但由于某种原因我的代码输出如下:
593.63
日志,
593.63
粘土,
593.63
金属
当它应该全部在一条线上时,为什么要这样做?这是我当前的代码:
var curAmntLogs = 448.34;
var curAmntClay = 448.34;
var curAmntMetal = 448.34;
var maxResources = 1000;
var curLogsPerSec = 1.67;
var curClayPerSec = 1.67;
var curMetalPerSec = 1.67;
function logs() {
curAmntLogs = curAmntLogs + curLogsPerSec;
if (curAmntLogs > maxResources) {
curAmntLogs = maxResources;
}
document.getElementById('logs').innerHTML = (curAmntLogs).toFixed(2);
}
function clay() {
curAmntClay = curAmntClay + curClayPerSec;
if (curAmntClay > maxResources) {
curAmntClay = maxResources;
}
document.getElementById('clay').innerHTML = (curAmntClay).toFixed(2);
}
function metal() {
curAmntMetal = curAmntMetal + curMetalPerSec;
if (curAmntMetal > maxResources) {
curAmntMetal = maxResources;
}
document.getElementById('metal').innerHTML = (curAmntMetal).toFixed(2);
}
setInterval(function(){ logs(); clay(); metal(); }, 1000);
我用它在网页上显示它:
<div id='logs'></div> Logs, <div id='clay'></div> Clay, <div id='metal'></div> Metal
我如何将所有内容集中在一条线上?谢谢!