Home > Web Front-end > JS Tutorial > body text

How to make the text box grow with the length of the text in JS_javascript skills

WBOY
Release: 2016-05-16 15:48:13
Original
1114 people have browsed it

The example in this article describes how JS implements the text box to grow with the length of the text. The specific implementation method is as follows:

<!Doctype HTML PUBLIC "-//W3c//DTD Html 1.0 Transitional//EN">
<html>
<head>
<title>文本框随文本的宽度而增长</title>
</head>
<script type="text/javascript">
function changeInputlength(cursor)
{
var getcount=document.getElementById("countFont");
var getText=document.getElementById("text");
getcount.innerHTML='<font>第'+(parseInt(getText.value.length)+1)+'个字符</font>';
cursor.size=getText.value.length+2;
}
</script>
<body>
<input type="text" size="3" id="text" onkeydown="changeInputlength(this);"/>
<span id="countFont"></span>
</body>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!