複製代碼代碼如下:
<!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>