dom操作之开关灯

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>
    <script>
    function changeImage() {
        element = document.getElementById('myimage');
        if (element.src.match("bulbon")) {
            element.src = "./images/pic_bulboff.gif";
        } else {
            element.src = "./images/pic_bulbon.gif";
        }
    }
    </script>
    
    <img id="myimage" onclick="changeImage()" border="0" src="./images/pic_bulboff.gif" width="100" height="180">
    <p>点击灯泡 开/关 灯</p>
</body>

</html>

posted @ 2016-06-05 12:28  TBHacker  阅读(1233)  评论(0编辑  收藏  举报