javascript - 在div jquery中通过鼠标选择查找SelectedText?

标签 javascript jquery

我想找到通过鼠标选择的div上的选定文本。我发现.select()选择的方法。但它不能解决我的问题。

我想要类似的东西:

 <div id='mydiv'>Lorem Ipsum is simply dummy text of the printing.</div>

当我使用鼠标选择简单文本时。我使用jquery发现了它。 或者其他选择的东西我想要得到它。

最佳答案

您不需要选择它。 您所需要做的就是添加一个点击处理程序。

document.addEventListener('touchend', handleTouchEnd, false);
function handleTouchEnd(e){
   console.log(e.target.innerHTML);// returns whatever is there in the div
   console.log(e.target.textContent);// better option, as it returns text only
}

关于javascript - 在div jquery中通过鼠标选择查找SelectedText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9924851/

相关文章:

javascript - Chrome 扩展 "Refused to load the script because it violates the following Content Security Policy directive"

javascript - json嵌套查找在javascript中使用基于字符串的键

jquery - 调整 jQuery Carousel 大小时隐藏下一张幻灯片

javascript - slideDown() slideUp() 反转

jquery - 使用带有滚动条问题的 jQuery UI Draggable?

javascript - jquery 支持多个项目?

javascript - 更改浏览器中的导航器以假装已安装该插件(使用 javascript)

javascript - 在 svg 上右键单击菜单

javascript - 获取选中的 Bootstrap 复选框的值

javascript - 不同的 ul 元素在水平移动的 div 中重叠