【发布时间】:2011-04-21 17:41:11
【问题描述】:
我有以下锚标记
<a href="http://www.google.com/">Google</a>
我知道如何从锚点获取 href:
alert($(this).attr("href"));
但是如何从锚标记中获取文本,即如何获取“Google”?
【问题讨论】:
我有以下锚标记
<a href="http://www.google.com/">Google</a>
我知道如何从锚点获取 href:
alert($(this).attr("href"));
但是如何从锚标记中获取文本,即如何获取“Google”?
【问题讨论】:
【讨论】:
如前所述,在使用 .text() 时,我将所有锚标记的文本组合到我的代码中:
HTML:
<div class="col-sm-2 jumbotron jumbotronUserRaces list-group list-group-
userRaces" id="listGroupUserRaces">
<a href="" class="list-group-item active">First item</a>
<a href="" class="list-group-item">Second item</a>
<a href="" class="list-group-item">Third item</a>
</div>
JS:
$("#listGroupUserRaces").click(function () {
alert($(this).text());
});
输出:
【讨论】: