且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查光标是否在指定标签之间

更新时间:2023-12-05 21:02:28

 您应使用span标签将标签之间的空格括起来. 然后,在jQuery中,使用 .mouseover() 函数.

 You should enclose the space between the tags with a span tag. Then, in jQuery, use the .mouseover() function.

示例:

<b>TAG1</b>
<span id="spacer">&nbsp;</span>
<strong>TAG2</strong>

<script type="text/javascript">
    $("#spacer").mouseover(function(){
        //Do stuff
    });
</script>

跨度必须有一些东西,因此在其中扔一个&nbsp;作为空格.

The span has to have something in it, so throw an &nbsp; in there as a space.

实时小提琴示例: http://jsfiddle.net/PrruT/

更新:

我不会为您完成全部功能,但我会告诉您可以这样设置:

I'm not going to do the whole function for you, but I'll tell you that you could set it up like this:

/* 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;
}