版权声明:本文为大都督作者的原创文章,未经 大都督 允许也可以转载,但请注明出处,谢谢! 共勉! https://blog.csdn.net/qq_37335220/article/details/84980446
1. 效果图
2. html代码
<!DOCTYPE html>
<html>
<head>
<title>3.9 使用toggleClass()方法切换元素css类别</title>
<style type="text/css">
.clsImg{border: solid 1px #666;padding: 3px;}
</style>
</head>
<body>
<img alt="" src="../img/pig.jpg" title="小猪变身" style="width:60px;height: 60px;">
<script src="../jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("img").click(function() {
//切换样式类别
$("img").toggleClass("clsImg");
})
});
</script>
</body>
</html>