示例html:
random = random.sample(kills, 4)
str_random = ", ".join(str(x) for x in random[:-1])
print("He has", str_random, "and", random[-1])
问题:如何使用jQuery将<ul class="navigation">
<li class="home">Home</li>
<li class="contact">Contact</li>
<li class="service">Services
<ul class="sub-menu">
<li>All Services</li>
<li>Cleaning</li>
<li>Repair</li>
</ul>
</li>
<li class="quote">Quote</li>
<li class="social">Social</li>
</ul>
及其所有子项移到<ul class="sub-menu">
之外?
例如:
<ul class="navigation">
这是一个带有非常奇怪的菜单设置的wordpress安装。 我试过了:
<ul class="navigation">
<li class="home">Home</li>
<li class="contact">Contact</li>
<li class="service">Services</li>
<li class="quote">Quote</li>
<li class="social">Social</li>
</ul>
<ul class="sub-menu">
<li>All Services</li>
<li>Cleaning</li>
<li>Repair</li>
</ul>
我认为应该有效,但没有做任何事情。
我也尝试过:
(function($){
$( ".service .submenu" ).appendTo( ".navigation" );
})(jQuery);
感谢您的帮助!
答案 0 :(得分:0)
使用appendTo
父元素,然后就可以了。
(function($){
$(".service .sub-menu").appendTo("#parent");
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="parent">
<ul class="navigation">
<li class="home">Home</li>
<li class="contact">Contact</li>
<li class="service">Services
<ul class="sub-menu">
<li>All Services</li>
<li>Cleaning</li>
<li>Repair</li>
</ul>
</li>
<li class="quote">Quote</li>
<li class="social">Social</li>
</ul>
</div>
答案 1 :(得分:0)
(function($){
var childmenu = $(".service .sub-menu").html();
$('#navigation').append(childmenu);
$(".service .sub-menu").remove();
})(jQuery);