首页 > Web开发 > 详细

jQuery之开关灯示例

时间:2017-10-16 17:33:48      阅读:250      评论:0      收藏:0      [点我收藏+]
准备jquery-3.2.1.js文件

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c11 {
            height: 100px;
            width: 100px;
            border-radius: 50%;
            border: 1px solid #cccccc;
            display: inline-block;
        }

        .c12 {
            background-color: yellow;
        }
    </style>
</head>
<body>

<div class="c11"></div>
<button id="switch" class="btn btn-default">开关</button>
<script src="jquery-3.2.1.js"></script>
<script>
    // id选择器
//    $("#i1")

//    $("#switch")[0].onclick = function () {
//        ....
//    }
//jQuery绑定事件
    $("#switch").on("click", function () {
        // 找灯泡
        $(".c11").toggleClass("c12");
    })

</script>
</body>
</html>

 

jQuery之开关灯示例

原文:http://www.cnblogs.com/yifugui/p/7677688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!