js改变网页背景颜色-js实现网页换肤功能

lxf2023-04-11 19:18:01
摘要

这篇文章主要为大家详细介绍了js实现网页换肤功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了js实现网页换肤的具体代码,供大家参考,具体内容如下

效果:

js改变网页背景颜色-js实现网页换肤功能

代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/CSS">
            *{
                margin: 0px;
                padding: 0px;
            }
            body{
                height: 100%;
                width: 100%;
                
            }
            #main{
                height: 720px;
                width: 100%;
                background-color: pink;
            }
            button{
                height: 15px;
                width: 15px;
                border: 1px solid #fff;
                margin: 10px 10px;
                
            }
            #red{
                background-color: red;
            }
            #green{
                background-color: green;
            }
            #blue{
                background-color: blue;
            }
            
        </style>
    </head>
    <body>
        <div >
            <button type="button"  onclick="red()"></button>
            <button type="button"  onclick="green()"></button>
            <button type="button"  onclick="blue()"></button>
        </div>
        
        <script type="text/javascript">
            var x=document.getElementById('main');
            function red(){
                x.style.backgroundColor='red';
                
                document.getElementById('red').style.border="3px solid white";
                document.getElementById('green').style.border="1px solid white";
                document.getElementById('blue').style.border="1px solid white";
                
            }
            function green(){
                x.style.backgroundColor='green';
                document.getElementById('green').style.border="3px solid white";
                document.getElementById('red').style.border="1px solid white";
                document.getElementById('blue').style.border="1px solid white";
            }
            function blue(){
                x.style.backgroundColor='blue';
                document.getElementById('blue').style.border="3px solid white";
                document.getElementById('red').style.border="1px solid white";
                document.getElementById('green').style.border="1px solid white";
            }
        </script>
    </body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。