下面是源碼需要瀏覽器支持html5 複製代碼代碼如下: <br />if(document.createElement("canvas")){ <br />if(document.getElementById("colorPicker").getContext){ <br />var can = document.getElementById("colorPicker"); <br />can.setAttribute("height",300); <br />can.setAttribute("height",300); <br />var cxt = can.getContext("2d"); <br />var gradient = cxt.createLinearGradient(0.5,0.5,0,150); <br />gradient.addColorStop(0,'#00ff00'); <br />gradient.addColorStop(0,'#00ff00'); <br />gradient. 1,'#ff0000'); <br />cxt.fillStyle=gradient; <br />cxt.fillRect(0,0,60,200); <br />var ox= can.offsetLeft <br />var oyopcan.off.offset; <br />var span = document.createElement("input"); <br />span.setAttribute("id","rgba"); <br />document.getElementById("textResult").appendChild(span); <🎜); >} <br />} <br />function showCurrentColor(e){ <br />var x = e.clientX - 8; <br />var y = e.clientY - 29; <br />var w = 10; <br />; if(document.createElement("canvas")){ <br />if(document.getElementById("colorPicker").getContext){ <br />var can = document.getElementById("colorPicker"); <br />var cxt = can.getContext("2d"); <br />var gradient = cxt.createLinearGradient(0.5,0.5,0,150); <br />var span = document.getElementById("rgba"); <br />var span = document.getElementById("rgba"); (ox,oy,10,200); <br />var imgData = imgDatas.data; <br />var g = imgData[4 *(w)*(y) (x)*4 1]; <br />var r = imgData [4 *(w)*(y) (x)*4]; <br />var b = imgData[4 *(w)*(y) (x)*4 2]; <br />var a = imgData[ 4 *(w)*(y) (x)*4 3]; <br />span.value="r=" r " g=" g " b=" b " a=" a; <br />document. getElementById("textResult").appendChild(span); <br />} <br />} <br />} <br />