当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Input文本框随着输入内容多少自动延伸的实现

Input文本框随着输入内容多少自动延伸的实现

2019年03月25日  | 移动技术网IT编程  | 我要评论

实例如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>无标题文档</title> 
<script language="javascript"> 
function checklength(which) { 
  var otextcount = document.getelementbyid("char");  
  icount = which.value.replace(/[^/u0000-/u00ff]/g,"aa"); 
  otextcount.innerhtml = "<font color=#ff0000>"+ icount.length+"</font>"; 
  which.style.border = '1px dotted #ff0000'; 
which.size=icount.length+2; 
} 
 </script> 
</head> 
<body> 
<input name="words" size="2"  onkeyup="checklength(this)"/> 
  <span id="char">0</span>个字符 
</body> 
</html>

以上这篇input文本框随着输入内容多少自动延伸的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网