+-下拉菜单

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="base.css">
<style>
ul{
display: none;
}
.show{
display: block;
}
</style>
</head>
<body>
<ol>
<li>
<button>+点击</button>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</li>
<li>
<button>+点击</button>
<ul>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
</li>
</ol>
<script src="jquery-3.2.1.min.js"></script>
<script>
$("button").click(function(){
if($(this).next("ul").hasClass('show')){
$(this).next("ul").removeClass('show');
$(this).html("+点击")
}else{
$(this).next("ul").addClass('show');
$(this).parent("li").siblings('li').children('ul').removeClass('show');
$(this).html("-点击")
$(this).parent("li").siblings('li').children('button').html("+点击")
}
})

</script>
</body>
</html>

posted @ 2018-04-10 18:00  大熊丨rapper  阅读(203)  评论(0编辑  收藏  举报