JavaScript實(shí)現(xiàn)顏色查看器
本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)顏色查看器的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)效果 方框中初始為白色 輸入框中輸入顏色代碼,點(diǎn)擊查看顏色,在上方即可出現(xiàn)對應(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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 編程語言PHP在Web開發(fā)領(lǐng)域的優(yōu)勢在哪?2. 詳解Android studio 動(dòng)態(tài)fragment的用法3. 圖文詳解vue中proto文件的函數(shù)調(diào)用4. 什么是python的自省5. 基于android studio的layout的xml文件的創(chuàng)建方式6. Spring Boot和Thymeleaf整合結(jié)合JPA實(shí)現(xiàn)分頁效果(實(shí)例代碼)7. 解決Android studio xml界面無法預(yù)覽問題8. Android如何加載Base64編碼格式圖片9. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)10. Springboot Druid 自定義加密數(shù)據(jù)庫密碼的幾種方案

網(wǎng)公網(wǎng)安備