gpt4 book ai didi

jquery - 获取所单击的 anchor 标记之间的内容

转载 作者:行者123 更新时间:2023-12-01 07:02:28 24 4
gpt4 key购买 nike

如果我有类似的东西:

<a>Content 1</a>
<a>Content 2</a>
<a>Content 3</a>

我想获取 anchor 标记之间的内容(被单击的单词),我该怎么做?链接是动态显示的,因此我无法向它们添加 id 属性。 (至少我想我不能。)

最佳答案

这应该可以选择全部:

$('a').each(function() { $(this).text(); /* do something with it */ });

如果您想获取 anchor 标记上的点击事件,但仅限那些没有 id 或 class 的标记,请尝试以下操作:

$('a').not('a[id]').not('a[class]').click(function() { $(this).text(); ... });

如果您只想执行一次操作:

$('a').not('a[id]').not('a[class]').one("click", function() { $(this).text(); ... });

关于jquery - 获取所单击的 anchor 标记之间的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1987990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com