我正在研究一个对我来说很好的水平菜单,但根据设计要求,我需要更改<div id="nav-subMenu"></div>
主/父菜单li
没有任何ul
或子菜单的高度。我写的 jquery 对我不起作用,我将不胜感激这方面的帮助。
这是一个jsFiddle的例子
if ($('#nav-wrapper ul li').has('ul'))
总是回来true
示例 jQuery
jQuery(document).ready(function () {
if ($('#nav-wrapper ul li').hasClass('active')) { //if it does have the class active
if ($('#nav-wrapper ul li').has('ul')) {
alert('aaaa');
$('#nav-subMenu').css("height", "30");
}
}
});
示例 HTML 代码
<div id="nav-wrapper">
<ul class="dropdown dropdown-linear" id="nav">
<li><span class="dir"><a href="#">Home</a></span></li>
<li><span class="dir"><a href="#">About Us</a></span></li>
<li><span class="dir"><a href="Articles.aspx?PageID=5&Language=en-us&ParID=0&Issue=5&CID=1">Articles</a></span></li>
<li class="active">
<span class="dir"><a href="Page.aspx?PageID=6&Language=en-us&ParID=0&Issue=5&CID=1">Categories</a></span>
<ul>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=18">Book Review</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=16">Business</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=3">Culture</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=2">Economy</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=19">Finance</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=17">Infrastructure</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=20">Lifestyle</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=21">Others</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=7">People</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=1">Politics</a></li>
<li><a href="Page.aspx?PageID=6&Language=1&ParID=6&Issue=1&CID=4">Sports</a></li>
</ul>
</li>
<li><span class="dir"><a href="News.aspx?PageID=3&Language=en-us&ParID=0&Issue=5&CID=1">News</a></span></li>
<li>
<span class="dir"><a href="Page.aspx?PageID=12&Language=en-us&ParID=0&Issue=5&CID=1">Archive</a></span>
<ul>
<li><a href="Page.aspx?PageID=1&Language=1&ParID=12&Issue=1&CID=1">106</a></li>
<li><a href="Page.aspx?PageID=3&Language=1&ParID=12&Issue=3&CID=1">102</a></li>
<li><a href="Page.aspx?PageID=4&Language=1&ParID=12&Issue=4&CID=1">103</a></li>
<li><a href="Page.aspx?PageID=5&Language=1&ParID=12&Issue=5&CID=1">109</a></li>
</ul>
</li>
<li>
<span class="dir"><a href="Multimedia.aspx?PageID=10&Language=en-us&ParID=0&Issue=5&CID=1">Multimedia</a></span>
<ul>
<li><a href="Videos.aspx?PageID=11&Language=1&ParID=10&Issue=1&CID=1">Video</a></li>
</ul>
</li>
</ul>
</div>
<div id="nav-subMenu"></div>
<div id="NewsTicker"> </div>
更新:Firebug 视图以了解何时应该触发 jquery 以向 DIV 添加高度