javascript HTML顏色選取器代碼

來源:互聯網
上載者:User
提示:您可以先修改部分代碼再運行

<p>HTML顏色選取器</p> <p>範圍:#000 - #FFF</p> <style><!-- .divColor div { float:left; width:5px; height:5px; line-height:0px; font-size:0px; cursor:pointer; } .divColor span { display:block; float:left; width:40px; height:20px; cursor:pointer; } .divColor .clear { height:auto; width:auto; clear:both; font-size:0px; line-height:0px; } --></style> <p> <input id="txtColor" onmouseover="selectColor(this);" type="text" /></p> <div class="divColor"> <script type="text/javascript">// <![CDATA[ function selectColor(o) { o.style.backgroundColor = '#FFF'; o.style.border = 'solid 10px ' + (o.value == '' ? 'black' : o.value); } function showColor(color) { document.getElementById('txtColor').style.border = 'solid 10px ' + color; } function setColor(color) { var txtColor = document.getElementById('txtColor'); txtColor.value = color; txtColor.style.backgroundColor = color; txtColor.select(); txtColor.focus(); } var c = '0123456789ABCDEF'; for (var r = 0; r < c.length; r++) { var color = '#' + c.charAt(r) + c.charAt(r) + c.charAt(r); document.write('<span onclick="setColor('' + color + '');" onmouseover="showColor('' + color + '');" + color + ';"> </span>'); } document.writeln('<div ></div>'); var begin = 0; for (var i = 0; i < 2; i++) { begin = i * 8; for (var r = 0; r < c.length; r++) { document.writeln('<div class="clear">'); for (var g = begin; g < begin + 8; g++) { for (var b = 0; b < c.length; b++) { var color = '#' + c.charAt(r) + c.charAt(g) + c.charAt(b); document.write('<div onclick="setColor('' + color + '');" onmouseover="showColor('' + color + '');" + color + ';"></div>'); } } document.writeln('</div>'); } } // ]]></script> </div>
提示:您可以先修改部分代碼再運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.