【发布时间】:2011-03-17 02:11:08
【问题描述】:
这是一个基本问题,但谷歌没有提供任何帮助。
我有一个网站,可以在上面运行 javascript。
在我的目录中,我有 index.html 和 index.css。对于 javascript 文件,我假设它应该被称为 index.js。
在我的 index.js 文件中,我有这个:
var countTime = 0; // Number of seconds
var redirectURL = "http://example.com"; // URL to direct to
countTime = (countTime+1)*1000;
function updateCount(){
countTime = countTime-1000;
if(document.getElementById("countdownDisplay"))
document.getElementById("countdownDisplay").innerHTML = (countTime/1000);
if(countTime <= 0)
location.href = redirectURL;
else
setTimeout("updateCount()",1000);
}
updateCount();
但是,当我使用浏览器访问该页面时,它不起作用。 我是否必须在我的 html 文件中做一些事情,比如 include index.js 之类的?
【问题讨论】:
-
仅供参考,您可以随意命名这些文件。将 HTML 文件命名为 index.html 将使其成为该目录的默认页面,但您的 CSS 和 JS 文件的名称仅对您有意义。我建议使用更多有意义的名称,这样更容易分辨哪个文件包含什么代码。随着您的网站变得越来越复杂,这一点变得越来越重要。
标签: javascript web