gpt4 book ai didi

javascript - 双击选择整个字符串

转载 作者:行者123 更新时间:2023-11-30 09:56:24 25 4
gpt4 key购买 nike

我正在将数据从 django 后端传递到我的浏览器,该后端可能包含 {{ string }} 的空格,例如 This is the sentenceH3ll0W0 !rd。双击时,我希望能够选择整个句子或字符串,以便可以复制。

HTML 的例子是

<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Book Title</th>
<th>Book Code</th>
</tr>
</thead>
<tbody>
{% for b in books %}
<tr>
<td>{{ b.title }}</td>
<td>{{ b.code}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

最佳答案

您可以像这样使用双击监听器:

HTML:

<p id="test">Here is some text</p>

Javascript:

document.getElementById('test').ondblclick = function(){
event.preventDefault();
var sel = window.getSelection();
var range = document.createRange();
range.selectNodeContents(this);
sel.removeAllRanges();
sel.addRange(range);
};

关于javascript - 双击选择整个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33738795/

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