如何检查游标是否在指定的标签之间
textarea
有一些formatted
文本,光标在某个地方。 我需要检查光标是否在某些特定标签之间。
示例: foo |
吧 。
isBetween(['b', 'strong']); // should return true in above case
我有返回textarea
cursor
position
的function
(有一些IE
问题,但现在满足我)。 所以,我需要的是isBetween()
function
。
谢谢你的帮助!
更新 :
qwerty|uiop
isBetween(['p']); // should also return true, because the cursor in not only between 'b', it is between 'p' too
您应该使用span
标记将标记之间的空格括起来。 然后,在jQuery中,使用.mouseover()
函数。
例:
TAG1 TAG2
跨度必须有一些东西,所以扔一个
在那里作为一个空间。
现场小提琴示例: http : //jsfiddle.net/PrruT/
更新:
我不打算为你做整个function,但我会告诉你,你可以这样设置:
/* I'm assuming you can figure out how to get the cursor position on your own, represented by var cursor */ function isBetween(selectorOne, selectorTwo){ var left = $(selectorOne).position().left; //Left position of the object var right = $(selectorTwo).position().left + $(selectorTwo).width(); //Right XY position of the object if (cursor > left && cursor < right) return true; else return false; }