js远远不止如此的强大
直接上代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
div.box{
width:300px;
padding:20px;
margin:20px;
border:4px dashed #ccc;
}
div.box span{
color:#999;font-style:italic;
}
div.content{
width:250px;
margin:10px 0;
padding:20px;
border:2px solid #ff6666;
}
</style>
</head>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js">
</script>
<body>
<p>这是一些文本。</p>
<div class="box">
<span>点击li则下移一位:</span>
<div class="content">
<ul>
<li>Glen</li>
<li>Tane</li>
<li>Jhon</li>
<li>Ralph</li>
</ul>
</div>
</div>
<script>
$(function(){
$(".content li").click(function() {
if($(this).next())
$(this).next().after($(this));
});
})
</script>
</body>
</html>
效果图片,点击li标签后会和下一个标签进行位置交换:
个人使用,获取子标签
// 选择第20个ul标签
$('.trends-ul>ul:nth-child(20)').next().after($('.trends-ul>ul:nth-child(20)'));