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. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)2. ajax post下載flask文件流以及中文文件名問題3. CSS自定義滾動(dòng)條樣式案例詳解4. 詳解CSS偽元素的妙用單標(biāo)簽之美5. SpringBoot+Shiro+LayUI權(quán)限管理系統(tǒng)項(xiàng)目源碼6. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法7. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法8. HTML <!DOCTYPE> 標(biāo)簽9. 關(guān)于Mysql-connector-java驅(qū)動(dòng)版本問題總結(jié)10. JavaScrip簡(jiǎn)單數(shù)據(jù)類型隱式轉(zhuǎn)換的實(shí)現(xiàn)
