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

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

I have following a tags:

Any tab1 Label
tab2 Label
Any tab3 Label<         


        
8条回答
  •  -上瘾入骨i
    2021-02-07 02:41

    function tellMyName() {
        var str = this.href.split("#")[1];
        alert(str);
    }
    

    Not all the time only the hash part will be displayed on the link. Sometimes the Host is added to the href. By splitting the href with the hash (#) and get the second part of the split string, you'll get what you want.

提交回复
热议问题