jquery——事件

1.click事件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>click事件</title>
    <script type="text/javascript" src="jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(function () {

            $('#btn').click(function () {
                //重复切换sty样式
                $('.box').toggleClass('sty');
            });
        })
        
    </script>
    <style type="text/css">
        .box{
            width:200px;
            height:200px;
            background-color: hotpink;
        }

        .sty{
            background-color: chartreuse;
        }
        
    </style>
</head>
<body>
    <input type="button" name="" value="切换" id="btn">
    <div class="box"></div>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/gaoquanquan/p/9205150.html