Javascript 从URL中删除锚点
我正在使用该代码滚动到锚点:Javascript 从URL中删除锚点,javascript,jquery,html,anchor,Javascript,Jquery,Html,Anchor,我正在使用该代码滚动到锚点: $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); ta
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
单击“继续”时,您可以在标题菜单上进行检查
但每次滚动到div时,我的URL都会变为www.mcsoftware.com.br/sitemc/#nameofdiv
可以把它取下来吗 阻止默认锚点单击:
$('a[href*=#]:not([href=#])。单击(函数(e){e.preventDefault();…})代码>谢谢你的回答,但它不起作用,我已经尝试过了。其他一些东西正在更改url。在HTML视图页面源代码中,你有一个名为跳转的函数。。。我想这就是问题所在。谢谢,我修好了。这是另一个滚动到anchor的脚本。