我试图在链接被点击后获取其哈希值。有任何想法吗?
例如:
这个链接
例如:
这个链接
index.html#needThis
这是我的结果:
index.htmlneedThis
我如何移除 'index.html' 文件?
$('#myselector').on('click', 'a', function(){
var hash = $(this).attr('href').replace('#', '') //get url
console.log(hash);
})
index.html
,而是只需获取哈希值即可。 - Nadav S.$(this).attr('href')
?!尽可能使用本地JS:this.href
具有完全相同的值,无需另一个库或函数调用。 - Martijn