JavaScript仅获取特定范围的选定文本
我正在尝试获取一个特定跨度的所有选定文本JavaScript仅获取特定范围的选定文本,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试获取一个特定跨度的所有选定文本 <span style="font-size:40px">Hi tTheee</span> <span style="font-size:20px">hello</span> <span style="font-size:20px">sdsds </span> Hi tTheee hello SDS 我正在使用window.getSelection() 如果用户选择了“hi t
<span style="font-size:40px">Hi tTheee</span> <span style="font-size:20px">hello</span> <span style="font-size:20px">sdsds </span>
Hi tTheee hello SDS
我正在使用window.getSelection()
如果用户选择了“hi tTheee hello”,这意味着他选择了2个跨距,但我只想获取hi tTheee。我该怎么做呢?获取所选跨距的索引并选择索引最小的跨距
如果用户选择“hi tTheee hello”,这意味着他选择了2个跨距,但我只想获取hi tTheee
所以我的理解是你想得到第一个跨度,用户选择了多少跨度
这里我使用mouseup函数来获得用户选择操作
$(document).on("mouseup",function(){
var range = window.getSelection().getRangeAt(0);
content = range.cloneContents();
var select = content.querySelectorAll('span');
console.log(select[0].innerHTML);//if u want all selected do loop
});
用户如何选择!通过鼠标选择单词!!更好的选择框或复选框用户通过鼠标选择。我用的是windo。getSelection@SamTengWong如何使用window.getSelection()获取所选的span id?