javascript实现文本域写入字符时限定字数

时间:2014-02-12    点击:83   
复制代码 代码如下:

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

<body>
<textarea id="text"cols="20" rows="5" onkeyup="sum ()" onfocus="focu()"></textarea>
<span id="span"></span>
</body>
<script>
function sum(){
var str =document.getElementById("text");
var cont=str.value;
var len=cont.length;
document.getElementById("span").innerHTML="您当前输入了"+len+"个字符";
if(len>=100){alert("您不能再写入了,已经达到最大限度!");
document.getElementById("text").value=cont.substr(0,99);
//实现100字最大限度 ,如果超过了,不在写入数据!
}
}
</script>
</html>
jquery+ajax+C#实现无刷新操作数据库数据的简单实例
JavaScript的strict模式与with关键字介绍
Javascript写入txt和读取txt文件示例
通过onmouseover选项卡实现img图片的变化
JavaScript中创建对象和继承示例解读
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved