本文主要用Html5中的控件来取得数值,然后通过设置rgb值来控制颜色。
代码如下:
<!DOCTYPE HTML>
<html><head>
<title>三生草</title>
</head>
<style type="text/css">
div{
width:300px;
height:300px;
border:2px double red;
}
</style>
<script language="javascript">
function sst()
{
document.getElementById("s").innerHTML="rgb("+document.getElementById("t1").value+","+document.getElementById("t2").value+","+document.getElementById("t3").value+")";
var sd = "rgb("+document.getElementById("t1").value+","+document.getElementById("t2").value+","+document.getElementById("t3").value+")";
document.getElementById("ssss").style.backgroundColor=sd;
}
</script>
<body>
<input type="range" id="t1" step="1" min="0" max="255" value="0" οnchange="sst()"><br/><br/>
<input type="range" id="t2" step="1" min="0" max="255" value="0" οnchange="sst()"><br/><br/>
<input type="range" id="t3" step="1" min="0" max="255" value="0" οnchange="sst()"><br/><br/>
<div id="ssss"></div>
<p id="s"></p>
</body>
</html>