This article example shares the specific code of JavaScript to implement the color viewer for your reference. The specific content is as follows Achieve results
Implementation Code<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Color Viewer</title> <style> #color { width: 150px; height: 150px; background-color: #fff; border: 1px solid #000; } </style> </head> <body> <div id="color"></div> <input id="inp" type="text" placeholder="Please enter the color code..." /> <button id="trans">View Color</button> <button id="rst">Restore</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> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed installation and use of SSH in Ubuntu environment
>>: Summary of common functions of PostgreSQL regular expressions
1. Problem There is a table as shown below, we ne...
This article does not have any quibbles, it is jus...
NextCloud You can share any files or folders on y...
This article provides some commonly used rewrite ...
Table of contents question Solution question Ther...
This article shares with you a compound motion im...
Several parts of Compose deal with environment va...
1. Introduction Presto is an open source distribu...
GUN Screen: Official website: http://www.gnu.org/...
How to solve the problem of being unable to acces...
Preface The explain command is the primary way to...
1.core file When a Segmentation fault (core dumpe...
1. After installing MySQL 5.6, it cannot be enabl...
Table of contents Introduction question Design 1:...
Introduction to Docker Docker is an open source c...