当前位置: 代码迷 >> JavaScript >> 用JavaScript限制textarea输入长度 (For: IE、Firefox .)
  详细解决方案

用JavaScript限制textarea输入长度 (For: IE、Firefox .)

热度:144   发布时间:2012-10-24 14:15:58.0
用JavaScript限制textarea输入长度 (For: IE、Firefox ...)

<!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" lang="gb2312">  
<head>  
<head>  
<title> Code:用JavaScript限制textarea输入长度 (For: IE、Firefox ...)</title>  
<meta http-equiv="content-type" content="text/html; charset=gb2312" />  
<meta name="author" content="枫岩,CNLei.y.l@gmail.com">  
<meta name="keywords" content="textarea,输入长度" />  
<meta name="description" content="用JavaScript限制textarea输入长度 (For: IE、Firefox ...)" />  
<style type="text/css" media="all">  
 body {font-size:14px;}  
</style>  
</head>  
<body>  
maxlength=10
  
<textarea maxlength="10" onkeyup="return isMaxLen(this)"></textarea>  


  
maxlength=20
  
<textarea maxlength="20" onkeyup="return isMaxLen(this)"></textarea>  

<script type="text/javascript">  
function isMaxLen(o){  
 var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):"";  
 if(o.getAttribute && o.value.length>nMaxLen){  
 o.value=o.value.substring(0,nMaxLen)  
 }  
}  
</script>  
</body>  
</html>
详细出处参考:http://www.jb51.net/article/5490.htm


详情请参考http://www.jb51.net/article/5490.htm
  相关解决方案