在div jquery中通过鼠标选择查找SelectedText? [英] Find SelectedText by mouse Selection in div jquery?
本文介绍了在div jquery中通过鼠标选择查找SelectedText?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在用鼠标选择的div上找到selected text
.我发现 .select()方法可供选择.但这并不能解决我的问题.
I want to find it out selected text
on div which select by mouse. I found out .select() method for select. but its not accomplish my problem.
我想要类似的东西:
<div id='mydiv'>Lorem Ipsum is simply dummy text of the printing.</div>
当我使用鼠标选择选择simply
文本时,我使用jquery
找到了它.
或其他我想得到的东西.
when i selected simply
text using mouse selection.i found it out using jquery
.
or something else another selected i want to get it.
推荐答案
您无需选择它. 您需要做的就是添加点击处理程序.
you don't need to select it. all you need to do is to add a click handler.
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
}
这篇关于在div jquery中通过鼠标选择查找SelectedText?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文