JavaScript下拉菜单无法按预期工作

时间:2016-12-18 09:36:46

标签: javascript html css3

我正在尝试使用JS添加活动类,但似乎无法正常工作。

这是代码

protected void Page_Load(object sender, EventArgs e)
{
    // ...
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        if (GridView1.Rows[i].Cells[4].Text == "industrial")
            GridView1.Rows[i].Visible = false;
    }
}

1 个答案:

答案 0 :(得分:0)

已更新:尝试此

var flag = 1;
$(document).ready(function(){
  $('#menuList li:not(:first-child)').click(function(){
    $('li').removeClass("active");
    $(this).addClass("active");
    $('#hm').css("display", "none");
    $('#hm').css("list-style", "none");
    flag = 1;
});
$('#menuList > li:first-child').click(function(){
  $('li').removeClass("active");
  $(this).addClass("active");
  if(flag == 1){
    $('#hm').css("display", "block");
    $('#hm').css("list-style", "square");
    flag = 0;
  } else {
    $('#hm').css("display", "none");
    $('#hm').css("list-style", "none");
    flag = 1;
  }
});
});
.active
{
  display:block;
    background-color:green;
}
 #hm{
  display: none;
  list-style: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="menuList">
<li class="menu active"><a href="#home">Home</a></li>
 <ul id="hm">
 <li><a href="#">home01</a></li>
 </ul>
<li class="menu"><a href="#gallery">gallery</a></li>
<li class="menu"><a href="#about">about</a></li>
<li class="menu"><a href="#contact">contact</a></li>
</ul>