【发布时间】:2015-02-03 10:43:06
【问题描述】:
我正在设置一个表格,格式如下。请原谅愚蠢的示例数据。所有这些实际上都是用json加载的,但是输出看起来是这样的:
<table id="famequotes">
<tr><td id="par001">It was the best of times, it was the worst of times.</td></tr>
<tr><td id="par002">Two things are infinite: the universe and human stupidity; and I'm not sure about the universe</td></tr>
<tr><td id="par003">In the jungle, the mighty jungle, the lion sleeps tonight...</td></tr>
</table>
在 $("#famequotes td") 上使用 mousedown 和 mouseup,我可以允许用户突出显示文本并捕获开始和结束行,并且类似地使用 onmouseover 捕获中间的所有行。
我想要做的是捕获起始行(我开始突出显示的表格单元格)的 SelStart 和最后一行的 sel...stop。
虽然我已经进行了研究和谷歌搜索,但我还没有找到答案。
MIchal Hainc 的回答真的很酷,但不是我想要的。
我可以看到选择框有什么用处,我很想将其合并。
但是,我真正想要的是,如果用户突出显示我在http://jsfiddle.net/vhyyzeog/1/ 中突出显示的文本,它将为 selStart 返回 3,为 selEnd 返回 12。我已经在跟踪突出显示的第一行和最后一行,所以我知道要应用 selstart 和 selend 到哪些行。
感谢您的帮助。
【问题讨论】:
标签: javascript jquery highlight