如何在另一个跨度上悬停时显示下一个跨度文本

时间:2015-04-10 13:08:58

标签: jquery html css

<asp:UpdatePanel ID="pnlParent" runat="server" UpdateMode="Conditional" ClientIDMode="Static">
    <ContentTemplate>
        <div class="hidOverflow smallPad">
            <div class="setFloatL halfWidth vertAlignT">
                <span class="profileLabel">Contact Number:</span>
            </div>
            <div class="setFloatL vertAlignT">
                <asp:Label ID="lblCliDate" ClientIDMode="Static" runat="server" Text="" CssClass="profileLabelValue"></asp:Label>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>


$(document).ready(function (e) {
    $("body").on("hover", ".profileLabel" , function () {
        alert($(this).next(".profileLabelValue").text());
    });
});

我希望在profileLabelValue课程span上方悬停时显示profileLabel课程span的文字。使用我的代码,一切都没有发生。

我如何实现这一目标,因为我目前正在尝试的方法无效。

3 个答案:

答案 0 :(得分:1)

因此我不得不使用hover而不是mouseover

我将代码更改为:

$(document).ready(function () {
    $("body").on("mouseover", ".profileLabel", function (e) {
        alert($(this).parent().next("div").find("span").first().text());
    });
});

以防其他人将来需要它。

答案 1 :(得分:1)

您应该尝试这样: -

$(document).ready(function () {
    $("body").on("mouseover", ".profileLabel", function (e) {
        alert($(this).parent().next("div").find("span").first().text());
    });
});

答案 2 :(得分:-1)

使用'mouseover'代替'hover'。

  

在jQuery 1.8中不推荐使用,在1.9中删除:名称“hover”用作字符串“mouseenter mouseleave”的简写。它为这两个事件附加单个事件处理程序,并且处理程序必须检查event.type以确定事件是mouseenter还是mouseleave。不要将“hover”伪事件名称与.hover()方法混淆,后者接受一个或两个函数。

Source