为什么我不能使用jQuery show方法显示<ul>元素?

时间:2016-10-07 18:48:30

标签: javascript jquery

我有<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>元素没有显示?我做错了什么?

2 个答案:

答案 0 :(得分:7)

您可能需要将# == Schema Information # # Table name: category_relationships # # child_id :integer not null # created_at :datetime not null # id :integer not null, primary key # parent_id :integer not null # updated_at :datetime not null # class CategoryRelationship < ActiveRecord::Base # Parent (Category) # ========================================================================================================== belongs_to :parent, class_name: "Category", inverse_of: :parent_child_relationships # Child (Category) # ========================================================================================================== belongs_to :child, class_name: "Category", inverse_of: :child_parent_relationships # Validations # ========================================================================================================== validates :parent, presence: true validates :child, presence: true end visibility更改为hidden才能显示元素

答案 1 :(得分:6)

JQuery&#39; show与添加css&#34; display:block&#34;大致相同。因此,ul上的展示率仍然相关。考虑使用&#34; display:none&#34;然后您可以使用.show()来显示它。

&#13;
&#13;
$("#showMe").on("click", function(){
  $("#inspectorMenu").show()
})
&#13;
<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>
&#13;
&#13;
&#13;