我想在用鼠标选择的div上找到selected text
。我找到了select的.select()方法。但这并不能解决我的问题。
我想要像这样的东西
<div id='mydiv'>Lorem Ipsum is simply dummy text of the printing.</div>
当我用鼠标选择simply
文本时,我用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
}