鍍金池/ 問(wèn)答/HTML/ 不能在當(dāng)前窗口調(diào)轉(zhuǎn)?

不能在當(dāng)前窗口調(diào)轉(zhuǎn)?

<a href="" class="loginOut" onclick="logOut()"                 target="_self">
    <span class="btn">退出</span>
</a>

function logOut(){

window.location.href='login.html';

}
怎么不能在當(dāng)前頁(yè)面調(diào)轉(zhuǎn)?

回答
編輯回答
乞許

加上完整的路徑吧

2017年9月29日 10:13
編輯回答
孤毒

把 a標(biāo)簽中的href寫(xiě)上 javascript:void(0),讓a標(biāo)簽的默認(rèn)跳轉(zhuǎn)行為不發(fā)生。
之前是因?yàn)樵趌ogOut()方法中還沒(méi)有開(kāi)始跳轉(zhuǎn)(確實(shí)執(zhí)行到了),頁(yè)面就被導(dǎo)向到當(dāng)前頁(yè)了(href為空)

<a href="javascript:void(0)" class="loginOut" onclick="logOut()"                 target="_self">
    <span class="btn">退出</span>
</a>
2017年5月7日 16:09