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
Table of contents 1. Recipe Collection 1.1 Projec...
This article example shares the specific code of ...
Download the official website Choose the version ...
Recently, when using kazam in Ubuntu 20.04 for re...
An error message appears when MySQL is started in...
Disclaimer: This password reset method can direct...
Table of contents Preface Component Introduction ...
Now if you want to use the video tag in a page, y...
This article example shares the specific code for...
@vue+echarts realizes the flow effect of China ma...
The box model specifies the size of the element b...
1. Connect to MYSQL Format: mysql -h host address...
Join query A join query refers to a matching quer...
Table of contents 1. Project construction 2: Dire...
Table of contents 1. Introduction 2. Output Infor...