美文网首页
click事件

click事件

作者: Alice丨殇 | 来源:发表于2018-11-07 18:54 被阅读0次

<!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">
(function(){ // 给按钮绑定click事件('#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">
(function(){('#btn').click(function(){
// ('.box').fadeOut();//淡出 //('.box').fadeIn();//淡入
// ('.box').fadeToggle();//切换淡入淡出 //('.box').toggle();//切换显示隐藏
$('.box').slideToggle();//切换上收和下展
})
})
</script>
</head>
<body>
<input type="button" name="" value="效果" id="btn">
<div class="box"></div>
</body>
</html>

相关文章

网友评论

      本文标题:click事件

      本文链接:https://www.haomeiwen.com/subject/ehfbxqtx.html