在鼠标悬停时显示特定div中的文本

时间:2015-06-26 07:15:42

标签: javascript jquery asp.net



function Hover(){
  if(a){
    //do something
    }
  else
    //disable delete button
    }

<div ID="dynamicDivFirstModule"  >

  <%--  Dynamic Div--%>
        <div id="dynamicDiv"  style="display:none; border:solid;" >
            <table>
                <tr>
                    <td class="auto-style1" rowspan="2">
                        <asp:TextBox ID="textbox" TextMode="MultiLine" runat="server" ReadOnly="true" style="overflow:auto;" Height="102px" Width="235px"></asp:TextBox>
                    </td>
                    <td id="hoverHere">
                        <asp:Label ID="Hovar" runat="server" Text="?"></asp:Label>
                        <p id="hover" class="masterTooltip" onmouseover="Hover();">?</p>
                                    
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="Delete" runat="server" Text="Delete" CssClass="removeDiv" />
                            
                    </td>
                </tr>
              
            </table>
        </div>
    
  <%--  Dynamic Div--%>
    </div>
&#13;
&#13;
&#13;

鼠标过来id="hover"时如何显示文字?我想显示条件文本?鼠标悬停在显示文本上如果a为真,则显示其他文本...文本应仅显示在id=DynamicDiv

2 个答案:

答案 0 :(得分:0)

假设您要在#target_element

中显示所需的文字
$('#hover').on('mouseenter', function() {
   if (a) {
      var text = 'a is true';
   } else {
      var text = 'a is false';
   }
   $('#DynamicDiv').find('#target_element').html(text);
}).on('mouseleave', function() {
   $('#DynamicDiv').find('#target_element').empty();
});

答案 1 :(得分:0)

只需按以下方式编写:

function Hover(){
    if(a){
         $("#selector").text('Whatever Text you want to display here');
    }
    else
         $("#selector").text('Someother Text you want to display here');
    }
}

注意 - #selector是您要显示文字的id的{​​{1}}!