JavaScript特效執行個體012-網頁拾色器

來源:互聯網
上載者:User

標籤:javascript

執行個體012                             網頁拾色器執行個體說明在網站中經常需要使用者自訂色彩來顯示某些資訊。這可以在網頁添加一個拾色器來實現。技術要點在本執行個體中僅使用216種瀏覽器安全的顏色,即所謂的Netscape色塊。這216種顏色分別代表0、51、102、153、204這5個顏色值以及每一種原色(即紅、綠、藍)。這些十進位數值對應的十六進位數分別為0x00、0x33、0x66、0x99、0xCC和0xFF。在HTML的顏色屬性中黑色是#000000,純紅色是#FF0000,純綠色就是#00FF00,純藍色是#0000FF,而白色是#FFFFFF。在實現網頁拾色器時需要應用JavaScript數組。建立數組可以有以下三種方法。(1)無參數調用。
<span style="white-space:pre"></span>var h = new Array()
(2)指定數組前n個元素的值var h = new Array(arglist)(3)指定具有的元素個數var h = new Array(n)實現過程(1)實現點擊色塊,彈出網頁拾色器網頁index.html
<!DOCTYPE html><html><head>    <meta charset="utf-8" />    <script type="text/jscript" language="javascript">function pp(field){var rtn = window.showModalDialog("color.html","","dialogWidth=220px;dialogHeight=200px;status=no;help=no;scrollbars=no")if(rtn!=null){field.style.background= rtn}return;}        </script>    </head>    <body>    <input type="text" readonly="yes" id="color" name="color" size=3 style="background:#000000" value = "" onclick = "pp(this)">    </body></html>
(2)網頁拾色器color.html
<script language="javascript">var h = new Array(6);h[0] = "FF";h[1] = "CC";h[2] = "99";h[3] = "66";h[4] = "33";h[5] = "00";function action(RGB){parent.window.returnValue = "#"+RGB;window.close();}function Mcell(R,G,B){document.write('<td bgcolor="#'+R+G+B+'">');document.write('<a href="#" onclick="action(\''+(R+G+B)+'\')">');document.write('<img border=0 height=12 width=12\')"alt=\'#'+R+G+B+'\'>');document.write('</a>');document.write('</td>');}function Mtr(R,B){document.write('<tr>');for (var i = 0; i <6; ++i){Mcell( R , h[i] , B );}document.write('</tr>');}function Mtable(B){document.write('<table cellpadding=0 cellspacing=0 border=0>');for(var i = 0;i<6;++i){Mtr(h[i],B);}document.write('</table>')}function Mcube(){document.write('<table cellpadding=0 cellspacing=0 border=0>');for(var i = 0;i<6;++i){if(i%3 == 0){document.write('<tr>')}document.write('<td bgcolor=#000000">');Mtable(h[i]);document.write('</td>')if(i%3==2){document.write('</tr>')}}document.write('</table>');}Mcube();</script>
註:style標籤的內容為css的知識,我們關注的是script標籤內的內容。這樣我們的這個執行個體就做好了。



JavaScript特效執行個體012-網頁拾色器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.