<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name='description' content='本文来源于Apollo个人整理,仅供参考!'>
    <title>点亮灯泡</title>
    <style type="text/css">
        div{
            width: 500px;
            height: 400px;
            background-color:lightgoldenrodyellow;
        }

    </style>
</head>
<body>
    <div>
        <img id="demo" src="./pic_bulboff.gif" alt="灯泡">
    </div>
    <script>
        document.getElementById('demo').onclick = function () {
            ele = document.getElementById('demo');
            if (ele.src.match('bulbon')){
                ele.src = './pic_bulboff.gif';
            }else{
                ele.src = './pic_bulbon.gif';
            }
        }
    </script>
</body>
</html>

 

图片pic_bulboff.gif

图片pic_bulbon.gif