开发者

jQuery Accordion parent link

I do want to be clickable to its link the parent menu after it show the sub menu,how can it this be done below are my codes

My HTML

        <ul id="menu">
            <li>
                <a href="http://stackoverflow.com/questions/ask">Menu 1 1</a>
                <ul>
                    <li><a href="http://yahoo.com/">Menu 1 Sub</a></li>
                </ul>
            </li>

            <li>
                <a href="http://stackoverflow.com/">Menu 2</a>
                <ul>
                    <li><a href="http://google.com/">Menu 2 Sub 1</a></li>
                    <li><a href="http://wiki.com/">Menu 2 Sub 2</a></li>
                </ul>
            </li>

       </ul>

My CSS

ul#menu, ul#menu ul {
  list-style-type:none;
  margin: 0;
  padding: 0;
  width:220px;
}

ul#menu a { font:bold 12px Arial, Helvetica, sans-serif;
  display: block;
  text-decoration: none;    
}

ul#menu li {
  margin-top: 1px;
}

ul#menu li a {
  background: #1c3f94;
  color: #fff;    
  padding: 0.5em;
}

ul#menu li a:hover {
  background: #000;
}

ul#menu li ul li a {
  background: #ccc;
  color: #000;
  padding-left: 20px;
}

ul#menu li ul li a:hover {
  background: #aaa;
  border-left: 5px #000 solid;
  padding-left: 15px;
}

My JS

function initMenu() {
  $('#menu ul').hide();
  $('#menu ul:first').show();
  $('#menu li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        return false;
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('#menu ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
 开发者_如何学C       }
      }
    );
  }
$(document).ready(function() {initMenu();});

LIVE DEMO


Don't return false when the first condition is true:

function initMenu() {
    $('#menu ul').hide();
    $('#menu ul:first').show();
    $('#menu li a').click(function () {
        var checkElement = $(this).next();
        if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            return true;
        }
        if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('#menu ul:visible').slideUp('normal');
            checkElement.slideDown('normal');
            return false;
        }
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜