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
How to center an element in the browser window He...
Problem [root@zh ~]# [root@zh ~]# [root@zh ~]# yu...
The following is my judgment based on the data st...
URL: http://hostname.com/contextPath/servletPath/...
1. Create and run a container docker run -it --rm...
introduction The company's recent Vue front-e...
1. Introduction Supervisor is a general process m...
Let’s take a look at a chestnut first EXPLAIN sel...
【author】 Liu Bo: Senior Database Manager at Ctrip...
1. Some problems encountered I remember when we w...
There are three ways to introduce CSS: inline sty...
1. Download the RPM package corresponding to Linu...
Preface Docker can configure environment variable...
In a project, you often need to use environment v...
Preface If we want to achieve the effect of onlin...