Javascript can';t在提交时重置位置哈希
我试图在每次按下提交按钮时将Javascript can';t在提交时重置位置哈希,javascript,jquery,hash,Javascript,Jquery,Hash,我试图在每次按下提交按钮时将窗口.location.hash设置为null或”,然后将hash设置为#bottom。基本上,我想要的是当他们按下某个提交按钮时,哈希值总是=#bottom。这就是我现在拥有的 window.setTimeout(function() { if (window.location.hash) { window.location.hash.
窗口.location.hash
设置为null
或”
,然后将hash设置为#bottom
。基本上,我想要的是当他们按下某个提交按钮时,哈希值总是=#bottom
。这就是我现在拥有的
window.setTimeout(function() {
if (window.location.hash) {
window.location.hash.replace("#", "");
} else {
window.location.href += "#bottom";
}
location.reload();
}, 1000)
但是,每次按下按钮时,哈希值总是保持不变。例如,如果散列是
mysite#reply
并且我提交了,它将保持mysite#reply
。非常感谢您的帮助。您需要将其设置为.replace()
返回的值
著名OR操作符的完美用例:window.location.href+=window.location.hash | |“#bottom”;
window.setTimeout(function() {
if (window.location.hash) {
window.location.href = window.location.hash.replace("#", "");
} else {
window.location.href += "#bottom";
}
location.reload();
}, 1000)