JavaScript實(shí)現(xiàn)顏色查看器
本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)顏色查看器的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)效果 方框中初始為白色 輸入框中輸入顏色代碼,點(diǎn)擊查看顏色,在上方即可出現(xiàn)對(duì)應(yīng)顏色 點(diǎn)擊復(fù)原,復(fù)原到初始的白色,同時(shí)清空輸入框的內(nèi)容<!DOCTYPE html><html lang='zh-CN'> <head><meta charset='UTF-8' /><title>顏色查看器</title><style> #color {width: 150px;height: 150px;background-color: #fff;border: 1px solid #000; }</style> </head> <body><div id='color'></div><input type='text' placeholder='請(qǐng)輸入顏色代碼...' /><button id='trans'>查看顏色</button><button id='rst'>復(fù)原</button> </body> <script>let trans = document.getElementById(’trans’);let color = document.getElementById(’color’);let inp = document.getElementById(’inp’);let rst = document.getElementById(’rst’);trans.addEventListener(’click’, () => { color.style.backgroundColor = inp.value;});rst.addEventListener(’click’, () => { color.style.backgroundColor = ’#fff’; inp.value = ’’;}); </script></html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)2. Spring注入Date類型的三種方法總結(jié)3. ASP基礎(chǔ)入門第二篇(ASP基礎(chǔ)知識(shí))4. HTML 絕對(duì)路徑與相對(duì)路徑概念詳細(xì)5. ASP實(shí)現(xiàn)加法驗(yàn)證碼6. PHP session反序列化漏洞超詳細(xì)講解7. PHP設(shè)計(jì)模式中工廠模式深入詳解8. ASP基礎(chǔ)知識(shí)Command對(duì)象講解9. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享10. PHP循環(huán)與分支知識(shí)點(diǎn)梳理
