Get hash value from url

前端 未结 5 1386
执念已碎
执念已碎 2020-12-24 07:06

I\'m trying to get the hash value after a link was clicked. Any ideas?

e.g.

The Link

index.html#needThis

This is my result:

5条回答
  •  萌比男神i
    2020-12-24 07:56

    Try this,

    $('#myselector').on('click', 'a', function(){
        var url = $(this).attr('href') //get url
        var arr = url.split('#');
        alert(arr[0]); //URL without hash #
        var hash = arr[1];
        console.log(hash);
    })​
    

提交回复
热议问题