【发布时间】:2017-07-25 10:31:53
【问题描述】:
我在一个网站上找到了这段代码, 我想知道这个功能是什么,做什么。 我知道 PHP、HTML、CSS 和 JavaScript, 但是我还没有学过 JQUERY 和 AJAX。我特别需要知道他们将东西放入颜色数组中的程序,它是随机的,还是有模式:
$('#onehour_next').css('backgroundColor', colors[(hours == 23 ? 0 : hours+1)]);
function doStuff()
{
current = new Date();
hours = current.getHours();
minutes = 59 - current.getMinutes();
seconds = 59 - current.getSeconds();
onehour.innerHTML = prettyTime(0, minutes, seconds);
if (colors.length === 0 || current.getSeconds() === 0)
init();
$('#onehour').css('backgroundColor', colors[hours]);
$('#onehour_next').css('backgroundColor', colors[(hours == 23 ? 0 : hours+1)]);
setTimeout(doStuff, 1000);
}
【问题讨论】:
-
colors数组看起来像是在此函数之外的某个地方创建的,只是在这里使用。在此函数中,没有任何内容被附加/附加到colors数组。 -
"but I haven't learned JQUERY and AJAX"- 这里有最小的 jQuery,没有 AJAX。"I especially need to know the routine they follow to put stuff in the colors array"- 此代码没有将任何内容放入colors。该变量在其他地方定义/填充。你到底在问这个代码是什么?当您调试此代码时,它的行为与您的预期有何不同? -
你们需要看完整的代码吗?
-
我们需要确切地知道您在问什么以及与该问题相关的代码。在更新您的答案之前,请查看此资源:stackoverflow.com/help/how-to-ask
-
但是如果你不懂 jQuery 并且你正在使用 jQuery,我的建议是去学习 jQuery。 api.jquery.com
标签: javascript jquery css