首页 > 代码库 > 利用range表单元素实现调色板

利用range表单元素实现调色板

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" charset="utf-8"/>
    <title>自定义调色器</title>
    <style>
        div{
            float:left;
            width:200px;
            height:200px;
            border:1px solid #ddd;
        }
        </style>
    <script>
    function $(id){
        return document.getElementById(id);
    }
    function color_change(){
        var r=$("txtRangeRed").value;
        var g=$("txtRangeGreen").value;
        var b=$("txtRangeBlue").value;    
        var color="rgb("+r+","+g+","+b+")";
        $("color").style.backgroundColor=color;
    }
    </script>
</head>
<body>
    <div>
        <form name="frm">
        <br>
            R:0<input type="range" min="0" max="255" step="1" value="0" id="txtRangeRed" onchange="color_change()">255<br><br>
            G:0<input type="range" min="0" max="255" step="1" value="0" id="txtRangeGreen" onchange="color_change()">255<br><br>
            B:0<input type="range" min="0" max="255" step="1" value="0" id="txtRangeBlue" onchange="color_change()">255
        </form>
    </div>
    <div id="color"></div>
</body>
</html>

 

利用range表单元素实现调色板