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

Bundling non-JavaScript static resources details

Table of contents 1. Custom import in packaging t...

Tutorial on installing MYSQL8.0 on Alibaba Cloud ESC

Open the connection tool. I use MobaXterm_Persona...

Summary of Linux Logical Volume Management (LVM) usage

Managing disk space is an important daily task fo...

A practical record of restoring a MySQL Slave library

Description of the situation: Today, I logged int...

Vue implements scroll loading table

Table of contents Achieve results Rolling load kn...

How to set list style attributes in CSS (just read this article)

List style properties There are 2 types of lists ...

Vue implements pull-down to load more

Developers familiar with Element-UI may have had ...

Analyze the difference between ES5 and ES6 apply

Table of contents Overview Function signature Opt...

js date and time formatting method example

js date time format Convert the date and time to ...

HTML Tutorial: HTML horizontal line segment

<br />This tag can display a horizontal line...

Vue.js implements image switching function

This article shares the specific code of Vue.js t...

Meta tags in simple terms

The META tag, commonly referred to as the tag, is...