【发布时间】:2023-03-19 13:37:01
【问题描述】:
我想通过单击来选择某些标签中的内容文本,例如code(准备复制粘贴)。
当你有 ID 时我找到了解决方案,但我的代码标签没有 ID:
<p>When I click <code>this code</code> I want it to be selected.</p>
<p>The code tags don't have IDs or tag names.</p>
<p>Here's some <code>other code</code>.</p>
这不起作用:
$("code").click(function(){
$(this).select();
});
似乎select() 仅适用于输入和文本区域。
【问题讨论】:
标签: jquery select textselection