<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>click事件</title>
<style type="text/css">
.box{
width: 200px;
height: 200px;
background-color: gold;
}
.sty{
background-color: green;
}
</style>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
('#btn').click(function(){
//重复切换sty样式
$('.box').toggleClass('sty');
})
})
</script>
</head>
<body>
<input type="button" value="切换" id="btn">
<div class="box"></div>
</body>
</html>
jQuery特殊效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery特殊效果</title>
<style type="text/css">
.box{
width: 200px;
height: 200px;
background-color: gold;
display: none;
}
</style>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
('#btn').click(function(){
// ('.box').fadeIn();//淡入
// ('.box').toggle();//切换显示隐藏
$('.box').slideToggle();//切换上收和下展
})
})
</script>
</head>
<body>
<input type="button" name="" value="效果" id="btn">
<div class="box"></div>
</body>
</html>
网友评论