简体   繁体   English

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

[英]How to display the next span text when hovered over another span

<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());
    });
});

I am looking to show the text of the profileLabelValue class span when hovered over profileLabel class span . 当悬停在profileLabelspan时,我希望显示profileLabelValuespan的文本。 With my code, nothing is happening. 使用我的代码,什么都没有发生。

How can I accomplish this, as the method I am currently trying is not working. 由于当前正在尝试的方法不起作用,我该怎么做。

So instead of hover I had to use mouseover . 因此,而不是hover我不得不使用mouseover

I changed the code to this: 我将代码更改为此:

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

In case someone else needs it in the future. 万一将来有人需要它。

You should try like this:- 您应该尝试这样:-

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

Use 'mouseover' instead of 'hover'. 使用“ mouseover”而不是“ hover”。

Deprecated in jQuery 1.8, removed in 1.9: The name "hover" used as a shorthand for the string "mouseenter mouseleave". 在jQuery 1.8中已弃用,在1.9中已删除:名称“ hover”用作字符串“ mouseenter mouseleave”的简写。 It attaches a single event handler for those two events, and the handler must examine event.type to determine whether the event is mouseenter or mouseleave. 它为这两个事件附加一个事件处理程序,并且处理程序必须检查event.type以确定该事件是mouseenter还是mouseleave。 Do not confuse the "hover" pseudo-event-name with the .hover() method, which accepts one or two functions. 不要将“ hover”伪事件名称与.hover()方法混淆,该方法接受一个或两个函数。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM