如题, 怎么样用js先刷新页面,然后定位到锚
window.location = window.location.pathname + '#comment';
window.location.reload();
现在这样做的,不过只有firefox下好使,其他都不灵呢,js高手来帮忙
window.location = window.location.pathname + '#comment';
window.location.reload();
现在这样做的,不过只有firefox下好使,其他都不灵呢,js高手来帮忙
function goAnchor(anchorStr){
var hash=window.location.hash;
var href=window.location.href;
return href.substr(0,href.length-hash.length);
window.location.href=hash==""?(href+anchorStr):(href.substr(0,href.length-hash.length)+anchorStr);
}
</script>
那简单阿,调用之前先判断下location含不含comment就行了。
含的话,先去掉,再加上!