2014-02-25 37 views
0

我有一個包含長段文本的div。我也有一個可以上下移動的滾動線。 我想獲取當前所在的文本,就像在下面的屏幕中一樣,您可以看到該行的位置在第3行。基本上突出顯示的行是絕對位置的div。請建議我如何獲取突出顯示的文本。如何通過突出顯示的位置獲得該行的文本

感謝

這裏是段落的截圖澄清

enter image description here

實際上是亮的行是移動選擇顏色的DIV可以用鼠標移動到向上或向下,我想要得到的文本是哪一段的哪一行。

有這樣的結構調查表

<table> 
<tr> 
<td> 
    <!-- here is the pragraph with many lines --> 

    <div>In 20 years our technology will reach a level of personalization that will enhance every moment of our lives. We’ll be more physically comfortable with the furniture we sit on and the products we hold; only the most relevant and personalized information from friends and family will reach us; and our movement in the digital world will be near telepathic.</div> 
</td> 
<td> 
    <!-- this is a div with absolute position to hightlight the line only --> 
    <div id="highlightingline" style="border-spacing: 5px; background-color: rgb(200, 226, 235); position: absolute; width: 55%; float: left; margin-left: -795px; opacity: 0.5; margin-top: 111px; color: black; border-collapse: separate; border-color: gray;">&nbsp;</div> 
</td> 
</tr> 
</table> 

請注意,我不想選擇通過鼠標選擇文本,因爲它已經工作正常,我只是想高亮線的文本,而不鼠標選擇。你可以說,我想獲得文本中突出顯示的行結束的行的文本。

請對此的jsfiddle我創建了一個演示一下,看看這個 滾動的內容,你會看到突出顯示的行我想要得到的文本,該文本行/文本/句子被高亮顯示

http://jsfiddle.net/qbhNw/1/

+1

你能提供的文本標記,這是很難說的東西,沒有它。 –

+0

有什麼建議嗎? –

+0

沒有建議? –

回答

2

Working Fiddle

var text = ""; 
if (window.getSelection) { 
    text = window.getSelection().toString(); 
} else if (document.selection && document.selection.type != "Control") { 
    text = document.selection.createRange().text; 
} 

alert(text); 
+0

我不想選擇鼠標選擇,因爲它已經在我的工作:)我想通過突出顯示的div選擇移動的文本 –

+0

我想通過突出顯示的div選擇移動的文本...請你elloborate –

+0

實際上突出顯示的行是可移動的選擇顏色的div可以用鼠標上下移動,我想要得到的文本是哪一段的行。 –

相關問題