how can i extract text after hash # in the href part from a tag?

前端 未结 8 1549
情话喂你
情话喂你 2021-02-07 02:22

I have following a tags:

Any tab1 Label
tab2 Label
Any tab3 Label<         


        
相关标签:
8条回答
  • 2021-02-07 03:03

    Try this -

    <a href="#tab1">Any tab1 Label</a>
    <a href="#tab2">tab2 Label</a>
    <a href="#tab3">Any tab3 Label</a>
    
    <script type="text/javascript">
    $('a').click(function(){
    alert(this.hash.split('#')[1]); //This will alert # part in clicked anchor tag
    });
    </script>
    
    0 讨论(0)
  • 2021-02-07 03:05
    function tellMyName() {
      alert(this.hash.substr(1));
    }
    
    $('a').click(tellMyName);
    
    0 讨论(0)
提交回复
热议问题