How to make an input text box change length according to its content

How to make an input text box change length according to its content
First:

Copy code
The code is as follows:

<input type="text" onkeydown="this.onkeyup();" onkeyup="this.size=(this.value.length>4?this.value.length:4);" size="4">

Among them, size="4" defines the initial size. If it is not defined here, change the 4 in this.size=(this.value.length>4?this.value.length:4); to 20. The default size of <input type="text"> is 20.

second:
If you define the width attribute in style, and want its width to change according to the content, aren't the two requirements contradictory? So here you can't define the width attribute in style.

<<:  SQL implementation of LeetCode (181. Employees earn more than managers)

>>:  Vue+SSM realizes the preview effect of picture upload

Recommend

A brief discussion on JavaScript shallow copy and deep copy

Table of contents 1. Direct assignment 2. Shallow...

How to install MySQL 5.7 on Ubuntu and configure the data storage path

1. Install MySQL This article is installed via AP...

Solve the problem of invalid utf8 settings in mysql5.6

After the green version of mysql5.6 is decompress...

JavaScript to implement limited time flash sale function

This article shares the specific code of JavaScri...

MySQL insert json problem

MySQL 5.7.8 and later began to support a native J...

Docker starts Redis and sets the password

Redis uses the apline (Alps) image of Redis versi...

MySQL sorting using index scan

Table of contents Install sakila Index Scan Sort ...

18 sets of exquisite Apple-style free icon materials to share

Apple Mug Icons and Extras HD StorageBox – add on...

Summary of how JS operates on pages inside and outside Iframe

Table of contents Get the content of the iframe o...

A brief analysis of React's understanding of state

How to define complex components (class component...

Detailed examples of Linux disk device and LVM management commands

Preface In the Linux operating system, device fil...

Usage of mysql timestamp

Preface: Timestamp fields are often used in MySQL...