A, jQuery exercises
This page is found in the id
i1
tag$('#i1')
This page find all
h2
labels$('h2')
This page find all
input
labels$('input')
This page find all styles class has
c1
a label$('.c1')
This page find all styles class has
btn-default
a label$('.btn-default')
This page find all styles class has
c1
tags and allh2
tags$('.c1,h2')
This page find all styles class has
c1
a label and id isp3
the label$('.c1,#p3')
This page find all styles class has
c1
tags and all styles class hasbtn
a label$('.c1,.btn')
Find on this page
form
all the tags in theinput
tag$('form input')
This page was found wrapped
label
in the labelinput
tag$('label input') // 等价于 $('label').find('input')
Found on this page immediately
label
behind the labelinput
tag$('label').next('input')
Id to find this page in
p2
all its peer behind the label and theli
label$('#p2').nextAll('li')
Id is found
f1
inside the label first input tag$('#f1 input').first()
Find the id value of
my-checkbox
the internal tag last input label$('#my-checkbox input').last()
Find the id value of
my-checkbox
the internal tag is not selected the input tag$('#my-checkbox input').not(':checked')
Find all containing
input
the labellabel
tag$('label input')
Second, the left side of the menu bar
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<title>左侧菜单示例</title>
<style>
.left {
position: fixed;
left: 0;
top: 0;
width: 20%;
height: 100%;
background-color: rgb(47, 53, 61);
}
.menu {
color: white;
}
.title {
text-align: center;
padding: 10px 15px;
border-bottom: 1px solid #23282e;
}
.items {
background-color: #181c20;
}
.item {
padding: 5px 10px;
border-bottom: 1px solid #23282e;
}
.hide {
display: none;
}
</style>
</head>
<body>
<div class="left">
<div class="menu">
<div class="item">
<div class="title">菜单一</div>
<div class="items">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
</div>
</div>
<div class="item">
<div class="title">菜单二</div>
<div class="items hide">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
</div>
</div>
<div class="item">
<div class="title">菜单三</div>
<div class="items hide">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
</div>
</div>
</div>
</div>
<div class="right"></div>
<script>
$(".title").click(function (){
$(".items").addClass("hide");
$(this).next().removeClass("hide");
// $(this).next().removeClass('hide').parent().siblings().find('.items').addClass('hide')
});
</script>