Home > Web Front-end > HTML Tutorial > Introduction to the method of changing the length of the input text box according to the content in it

Introduction to the method of changing the length of the input text box according to the content in it

高洛峰
Release: 2017-03-06 16:06:25
Original
3556 people have browsed 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">
Copy after login


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 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template