Sometimes the input box is small, and you want to see a prompt box with a magnified input content after entering the content. Implementation ideas
Note that this is the keyboard release event. Do not use the keyboard press event: keydown or keypress. The typed words are not entered when the keyboard is pressed. The typed words are entered only when the keyboard is released. Code example: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Simulate JD Express tracking number query</title> <style> * { margin: 0; padding: 0; } input { outline-style: none; } .search { position: relative; width: 220px; margin: 100px auto; } .info { display: none; position: absolute; top: -40px; left: 0; width: 170px; padding: 5px 0; font-size: 18px; line-height: 20px; border: 1px solid rgba(0, 0, 0, .2); box-shadow: 0px 2px 4px rgba(0, 0, 0, .2); } .info::before { content: ''; width: 0; height: 0; position: absolute; top: 28px; left: 18px; border: 8px solid #000; border-color: #fff transparent transparent; border-style: solid dashed dashed; } </style> </head> <body> <div class="search"> <div class="info">(*´▽`)ノノ</div> <input type="text" class="express" placeholder="Please enter the express number you want to query"> <input type="button" value="Query"> </div> <script> var expressNo = document.querySelector('.express'); var info = document.querySelector('.info'); expressNo.addEventListener('keyup', function() { console.log(expressNo.value); console.log(info.innerHTML); if (this.value == '') { info.style.display = 'none'; } else { info.style.display = 'block'; info.innerHTML = this.value; } }); // Lose focus, hide the box expressNo.addEventListener('blur', function() { info.style.display = 'none'; }) //Get the focus event and display the box expressNo.addEventListener('focus', function() { if (this.value !== '') { info.style.display = 'block'; } }) </script> </body> </html> Page effect: This is the end of this article about how to use javascript to implement input box content prompts and hidden functions. For more related js input box content prompts and hidden content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of Docker container data volumes
>>: MySQL 8.0.22 installation and configuration graphic tutorial
The Docker container that has been running shows ...
background Speaking of MySQL deadlock, I have wri...
Table of contents Introduction Install Display Fi...
1. Parent div defines pseudo-classes: after and z...
Vue components are connected, so it is inevitable...
Preface The apt-get command is a package manageme...
[LeetCode] 177.Nth Highest Salary Write a SQL que...
This article shares the specific code of the vue-...
I have been relearning HTML recently, which can be...
This article shares with you how to use the Vue s...
Triggers can cause other SQL code to run before o...
1. View the detailed information of all current c...
Table of contents need: Ideas: lesson: Share the ...
Table of contents What is Docker deploy 1. Pull t...
vue-element-admin import component encapsulation ...