87,910
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
<script src="jquery-3.1.0.js"></script>
<style>
#box1{
width: 100px;
height: 100px;
background: #ee88aa;
margin: 20px auto;
}
#box2{
width: 100px;
height: 100px;
background: #7821ff;
margin: 20px auto;
}
#box1 #box1-2{
background: yellow;
width: 50px;
height:50px;
margin:auto;
}
</style>
</head>
<body>
<div id="box1" class="myclass">
一级div
<div id="box1-2">
二级div
</div>
</div>
<div id="box2" class="notmyclass">notmyclass</div>
</body>
</html>
<script>
$(document).ready(function () {
$(".myclass>#box1-2").click(function () {
$(this).html("我变了").css('background','#eee')
});
$('div.myclass').click(function () {
$(this).css('background',"#ee88ff");
});
})
</script>