Home > Article > Web Front-end > Introduction to the method of changing the length of the input text box according to the content in it
This article mainly introduces how to make an input text box change the length as the content length changes. The implementation principle is very simple. You will know it after reading it.
First:
The code is as follows:
<input type="text" onkeydown="this.onkeyup();" onkeyup="this.size=(this.value.length>4?this.value.length:4);" size="4">
size="4" is the initial size defined. If it is not defined here, then this.size=( this.value.length>4?this.value.length:4); change the 4 inside to 20, and the default size of 23efcc05e98690ceeb219581933e4231 is 20
Second:
If you define the width attribute in style and want its width to change according to the content, wouldn't the two requirements be contradictory? So the width attribute cannot be defined in style here.
More input For an introduction to the method of changing the length of a text box according to its content, please pay attention to the PHP Chinese website for related articles!