为什么我不能显示'元素的显示方法

Why can't I display <ul> element using jQuery show method?

本文关键字:显示 元素 方法 不能 为什么      更新时间:2023-09-26

我有这个<ul>元素:

<ul id="inspectorMenu" class="nav pull-left" style="visibility: hidden;">
    <li style="display: inline-block;text-align: center; max-height:35px;">
        <a class="navbar-brand" ui-sref="sites.list" style="padding: 11px 09px;" title="אתרים">
            <i class="glyphicon glyphicon-tree-conifer"></i>
        </a>
    </li>
    <li style="display: inline-block;text-align: center;max-height:35px;">
        <a class="navbar-brand" ui-sref="sitesDamages.sitesList" style="padding: 11px 09px;" title="אירועים">
            <i class="glyphicon glyphicon-exclamation-sign"></i>
        </a>
    </li>
</ul>

我调用这个jQuery行来显示<ul>元素:

$("#inspectorMenu").show();

但是没有显示<ul>元素。

知道为什么不显示<ul>元素吗?我做错了什么?

您可能需要将visibilityhidden更改为visible以显示元素

JQuery的show与添加css "display: block"大致相同。因此,ul上的可见性仍然是相关的。考虑使用"display: none",然后你可以使用.show()来显示它。

$("#showMe").on("click", function(){
  $("#inspectorMenu").show()
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="inspectorMenu" class="nav pull-left" style="display: none;">
  <li style="display: inline-block;text-align: center; max-height:35px;"><a class="navbar-brand" ui-sref="sites.list" style="padding: 11px 09px;" title="אתרים"><i class="glyphicon glyphicon-tree-conifer">Some Text</i></a>
  </li>
  <li style="display: inline-block;text-align: center;max-height:35px;"><a class="navbar-brand" ui-sref="sitesDamages.sitesList" style="padding: 11px 09px;" title="אירועים"><i class="glyphicon glyphicon-exclamation-sign">Some More Text</i></a>
  </li>
</ul>
<button id="showMe">Show Me</button>