[英]Double click word JavaScript window.getSelection in two INS tag
My HTML is: 我的HTML是:
<p><ins data-id="1">111</ins><ins data-id="2">222</ins></p>
The output of this code is: 此代码的输出是:
If I double click the word, it's selecting the complete word, like this: 如果我双击该单词,它会选择完整的单词,如下所示:
But I want to select the letters based on the INS tag data-id
但我想根据INS标签
data-id
选择字母
Ex:- if I double click the 111
I want to select only 111
like this: 例如: - 如果我双击
111
我想只选择111
这样:
How to modify the default double click selection to JavaScript selection? 如何修改默认的双击选择到JavaScript选择?
I tried the following code: 我尝试了以下代码:
var containerid = $(e.currentTarget);
if (window.getSelection) {
var range = document.createRange();
range.selectNode(containerid);
var sel = window.getSelection()
sel.removeAllRanges();
sel.addRange(range);
}
But it's not working as expected. 但它没有按预期工作。
<p><ins data-id="1">111</ins>​<ins data-id="2">222</ins></p>
你可以在它们之间放置一个零宽度空间 : ​
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.