我是jscript的新手.我在javascript中使用此代码返回主页
function gohome()
{
window.location="../index.html"
}
Run Code Online (Sandbox Code Playgroud)
我在这段代码中调用该函数
'<a accesskey="h" id="home" href="javascript:gohome();">Home<\/a>' +
Run Code Online (Sandbox Code Playgroud)
单击页面时会有链接,它会调用gohome()函数.但是同样的链接出现在索引页面上.点击它时显示找不到页面.
如何在index.html页面中隐藏此链接?
谁能帮我??
添加.href:
function gohome()
{
window.location.href="../index.html"
}
Run Code Online (Sandbox Code Playgroud)
我认为您不需要一个 javascript 函数就可以回家,您可以这样做:
<a accesskey="h" id="home" href="../index.html">Home<\/a>
Run Code Online (Sandbox Code Playgroud)
如果您不希望它显示在主页上,但假设主页是 example.com/index.html,您可以执行类似的操作
if(window.location.pathname=="/index.html"){
document.getElementById('home').style.display = 'none';
}
Run Code Online (Sandbox Code Playgroud)
不是在函数中,而是在源代码或头部中的链接之后的某个时间调用。