-1

我有一些菜单循环编码,如何在开始循环之前和结束循环之后插入一些 div。我尝试使用 .prepend 但没有工作。

<li class="mega-menu-fullwidth dropdown"><a href='#'>Features</a>
    <ul class="dropdown-menu">
<!-- div open goes here <li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif"> -->
            <!-- Start First Loop -->
            <a href='javascript:void(0);'>submega</a>
            <div class="col-md-3 equal-height-in">
            <ul class="list-unstyled equal-height-list">
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
            </ul>
            </div><!-- End First Loop -->
<!-- div close goes here </div></div></div></li> -->
    </ul>
</li>

任何可以帮助我?谢谢

$(function(){ $('.mega-menu-fullwidth .dropdown-menu').prepend('<li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif"></div></div></div></li>'); });

不工作。

4

1 回答 1

0

希望能帮助到你。

<li class="mega-menu-fullwidth dropdown"><a href='#'>Features</a>
    <ul class="dropdown-menu">
<!-- div open goes here <li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif"> -->
            <!-- Start First Loop -->
            <a href='javascript:void(0);'>submega</a>
            <div class="col-md-3 equal-height-in">
            <ul class="list-unstyled equal-height-list">
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
            </ul>
            </div><!-- End First Loop -->
<!-- div close goes here </div></div></div></li> -->
    </ul>
</li>

var appendedHtml = '<li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif">'+$('ul.dropdown-menu').html()+'</div></div></div></li>';
$('ul.dropdown-menu').html(appendedHtml);

$('ul.equal-height-list').eq(0).find('li').eq(0).remove();
$('ul.equal-height-list').eq(0).prepend('<h3>One</h3>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<li class="mega-menu-fullwidth dropdown"><a href='#'>Features</a>
    <ul class="dropdown-menu">
<!-- div open goes here <li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif"> -->
            <!-- Start First Loop -->
            <a href='javascript:void(0);'>submega</a>
            <div class="col-md-3 equal-height-in">
            <ul class="list-unstyled equal-height-list">
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
            </ul>
            </div><!-- End First Loop -->
<!-- div close goes here </div></div></div></li> -->
    </ul>
</li>

于 2017-04-09T18:23:52.657 回答