2012-03-29 51 views
0

我想找出selected text div上的鼠標選擇。我找到了.select()選擇的方法。但它不能完成我的問題。通過鼠標在div jquery中選擇SelectedText?

我想是這樣的:

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

當我選擇用鼠標selection.i simply文本中找到它使用jquery。 或其他選擇我想要得到它。

回答

2

你不需要選擇它。 所有你需要做的就是添加一個點擊處理程序。

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 
}