2012-05-07 46 views
1

當用戶突出顯示該網頁存在的一部分,我怎麼進入一段HTML或文本的用戶已選擇。訪問高亮/選定的文本

貌似jquery select僅適用於輸入元素。

基本上什麼是訪問在CSS3 ::selection選擇已生效部分的簡單方法。

+0

可能重複:http://stackoverflow.com/questions/5379120/jquery-get-the-highlighted-text – kei

+0

我想已經有一個解決方案發布 HTTP: //stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse 嘗試觀察別人質疑和答案先那麼只有發佈問題。 – mesimplybj

回答

0

你可以試試:

document.getSelection() 

var text = ''; 
if (window.getSelection) 
    { 
     text = window.getSelection(); 
    } 
    else if (document.getSelection) 
    { 
     text = document.getSelection(); 
    } 
    else if (document.selection) 
    { 
     text = document.selection.createRange().text; 
    } 
    else return;