程序代碼 程序代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=big5">
<title>檢查輸入長度</title>
</head>
<body>
<script language="javascript">
function changeText(objElement) {
    var oTextCount = document.getElementById("txtCount");  
    iCount = objElement.value.length;
    oTextCount.innerHTML = "<font color=red>"+ iCount+"</font>";    
}
</script>
目前字數總共:<span id="txtCount"><font color="red">0</font></span> 字<br>
<textarea name="message" rows="6" cols="60" wrap="virtual" tabindex="2" onkeyup="changeText(this);"></textarea>
</body>
</html>

點擊下載範例...

程序代碼 程序代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>檢查中文及英文字數</title>
</head>
<body>
<script language="javascript">
function changeText(objElement) {
    var oTextCount = document.getElementById("txtCount");
var tmp="";
    tmp=objElement.value.replace(/[^\u0000-\u00ff]/g," a a ");
    tmp=tmp.replace(/\b([a-z0-9]+)\b/gi," a ");
    tmp=tmp.replace(/\s/g,"");
    oTextCount.innerHTML = "<font color=red>"+ tmp.length+"</font>";    
}
</script>
目前字數總共:<span id="txtCount"><font color="red">0</font></span> 字<br>
<textarea id="msg" rows="6" cols="60" wrap="virtual" tabindex="2" onkeyup="changeText(this);"></textarea>
</body>
</html>


點擊下載範例...


arrow
arrow
    全站熱搜

    kevin0523 發表在 痞客邦 留言(0) 人氣()