-1

当我的鼠标在 Label1 上时,我想将 Label2 显示在它附近。然后,当我的鼠标离开 Label1 时,我想隐藏 Label2。我尝试使用以下代码。我的javascript很差。

    <script language="javascript" type="text/javascript">
    function LabelHover()
    {
        document.getElementById('Label1').style.display = 'inherit';
    }

    function Labelleave() 
    {
        document.getElementById("Label1").style.display='none';
    }
    </script>

</head>
<body>
    <asp:Label ID="Label1" runat="server" Text="Hello" Height="120" Width= "120" ForeColor="Brown" style=" left:220px; border:groove; top:15px " >
    </asp:Label>

    <asp:Label ID="Label2" runat="server" Text="Disclaimer" Height="17" Width= "100" ForeColor="Brown" onmouseover="LabelHover()" onmouseout="Labelleave()" style=" left:220px; " >
    </asp:Label>
4

2 回答 2

0

由于您要显示或隐藏 Label2 取决于 Label1 那么您必须在 Label1 上添加 onmouseover() 和 onmouseout() 而不是 Label2

<asp:Label ID="Label1" runat="server" Text="Hello" Height="120" Width= "120" onmouseover="LabelHover()" onmouseout="Labelleave()" ForeColor="Brown" style=" left:220px; border:groove; top:15px " >
    </asp:Label>

    <asp:Label ID="Label2" runat="server" Text="Disclaimer" Height="17" Width= "100" ForeColor="Brown"  style=" left:220px; " >
    </asp:Label>

Javascript:

<script language="javascript" type="text/javascript">
    function LabelHover() {
        document.getElementById('Label2').style.visibility = 'visible';
    }

    function Labelleave() {
        document.getElementById('Label2').style.visibility = 'hidden';
    }
    </script>
于 2013-08-04T17:32:32.687 回答
0

这是我的javascript:

<script language="javascript" type="text/javascript">
    function LabelHover() {
        document.getElementById('<%= Label1.ClientID%>').style.display = 'inherit';
    }

    function Labelleave() {
        document.getElementById('<%= Label1.ClientID%>').style.display = 'none';
    }
</script>

和标记:

<asp:Label ID="Label1" runat="server" Text="Hello" Height="120" Width= "120" ForeColor="Brown" style=" left:220px; border:groove; top:15px; float:left; " >
</asp:Label>

<asp:Label ID="Label2" runat="server" Text="Disclaimer" Height="17" Width= "100" ForeColor="Brown" onmouseover="LabelHover()" onmouseout="Labelleave()" style=" left:220px;float:left; " >
</asp:Label>
于 2013-08-04T16:54:59.203 回答