如何从标签的href部分中的井号#后提取文本? [英] how can i extract text after hash # in the href part from a tag?

查看:88
本文介绍了如何从标签的href部分中的井号#后提取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下标签:

<a href="#tab1">Any tab1 Label</a>
<a href="#tab2">tab2 Label</a>
<a href="#tab3">Any tab3 Label</a>
<script>
function tellMyName()
{
    alert(this.href);
}

</script>

现在,我想将tellMyName函数绑定到所有a标签,如果单击任何tab1标签,则获取 tab1 ,如果单击 tab2 ,则获取 tab2 点击strong> tab2标签,依此类推...

Now i want to bind the tellMyName function to all the a tags and get tab1 if Any tab1 Label is clicked, tab2 if tab2 Label is clicked and so on...

推荐答案

function tellMyName() {
  alert(this.hash.substr(1));
}

$('a').click(tellMyName);

这篇关于如何从标签的href部分中的井号#后提取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆