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='請輸入顏色代碼...' /><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>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 解決Android Studio 格式化 Format代碼快捷鍵問題2. php解決注冊并發(fā)問題并提高QPS3. 完美解決vue 中多個(gè)echarts圖表自適應(yīng)的問題4. 在Chrome DevTools中調(diào)試JavaScript的實(shí)現(xiàn)5. Springboot 全局日期格式化處理的實(shí)現(xiàn)6. SpringBoot+TestNG單元測試的實(shí)現(xiàn)7. Java使用Tesseract-Ocr識(shí)別數(shù)字8. vue實(shí)現(xiàn)web在線聊天功能9. JS原生2048小游戲源碼分享(全網(wǎng)最新)10. Python使用urlretrieve實(shí)現(xiàn)直接遠(yuǎn)程下載圖片的示例代碼
