惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
V
Visual Studio Blog
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
B
Blog
I
InfoQ
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
H
Help Net Security
博客园 - Franky
宝玉的分享
宝玉的分享
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家

博客园 - 天山雪王

[ubuntu]安装vmware时找不到c header files的小问题 linux tar命令【转】 ubuntu安装配置方法【转】 什么是 EXIF 我认为比较经典的cookie欺骗的文章,还附带nc提交和WinSock Expert基本用法。原作者---海洋---- 网页wmp可视化效果 排序 高亮关键字 正则表达式不包含align该怎么写 [js]删除以 [ 开始以 ]结尾且不含:内容 Javascript的caller,callee,call,apply概念 innerHTML中的JS运行问题 几个比较好的图片播放代码一 几个比较好的图片播放代码二 IE里的探索之创建具有良好行为的自定义元素(htc,behavior) 网页代码常用小技巧 干掉不让frame的网页 Windows附带的计算器的错误 PS后期处理:怎么样让MM的脸更美白通透
JS检查限制字符,单词个数
天山雪王 · 2006-12-23 · via 博客园 - 天山雪王

转自:http://bbs.blueidea.com/thread-2704372-1-1.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>
<script language="javascript">
<!--
var maxWord=10; //中文及英文最大字數
var maxCharacter=50; //字元字數

//檢查輸入中文及英文字數
function changeTextWord(objElement) {
    var sng=false;
    if(changeText(objElement)){sng=true;}else{return false;}
    var oTextCountWord = $("txtCountWord_"+objElement.id);
    var tmp="";
 tmp=objElement.value.replace(/[^\u0000-\u00ff]/g," a ");
 tmp=tmp.replace(/\b([a-z0-9]+)\b/gi,"a");
 tmp=tmp.replace(/\s/g,"");
 if(tmp.length>maxWord){
    sub(objElement);
    if(event.keyCode==8){sng=true;}else{sng=false;};
    }else{
    sng=true;
    } 
    oTextCountWord.innerHTML = "<font color=#0000FF>"+ tmp.length +"</font>";
    objElement.style.background = '#FFFFFF' ;
 return sng;
}

//檢查輸入長度
function changeText(objElement) {
    var oTextCount = $("txtCount_"+objElement.id);
    //iCount = objElement.value.length;
    iCount = objElement.value.replace(/[^\u0000-\u00ff]/g,"aa").length;
    if(iCount>maxCharacter){
    sub(objElement);
    if(event.keyCode!=8){return false;};
    }
    oTextCount.innerHTML = "<font color=#0000FF>"+ iCount+"</font>";
    return true;
}

function resizeEditor(change,obj) {
var newheight = parseInt($(obj).style.height,10) + change;
if(newheight >= 20) {
$(obj).style.height = newheight + 'px';
}
}
function $(obj){
return document.getElementById(obj);
}
function sub(obj){
obj.value=obj.value.substring(0,obj.value.length-1);
changeTextWord(obj);
}
-->
</script>
</head>
<body>
<form>
目前字數總共:<span id="txtCountWord_taAbObjective"><font color="#0000FF">0</font></span> 字(Word),<span id="txtCount_taAbObjective"><font color="#0000FF">0</font></span> 字元(Character)<br>
<textarea id="taAbObjective" rows="6" cols="60" wrap="virtual" onkeydown="return changeTextWord(this);" onkeyup="return changeTextWord(this);" onblur="changeTextWord(this)" onpaste="return changeTextWord(this);" ondrag="javascript:return false;" style="border:1px solid #000000; height:100px;"></textarea>
<div class="editor_textexpand"><img src="images/common/bb_contract.gif" width="11" height="21" title="收縮編輯框" alt="收縮編輯框" onclick="resizeEditor(-20,'taAbObjective')" /><img src="images/common/bb_expand.gif" width="11" height="21" title="擴展編輯框" alt="擴展編輯框" onclick="resizeEditor(20,'taAbObjective')" /></div>

目前字數總共:<span id="txtCountWord_taAbObjective2"><font color="#0000FF">0</font></span> 字(Word),<span id="txtCount_taAbObjective2"><font color="#0000FF">0</font></span> 字元(Character)<br>
<textarea id="taAbObjective2" rows="6" cols="60" wrap="virtual" onkeydown="return changeTextWord(this);" onkeyup="return changeTextWord(this);" onblur="changeTextWord(this)" onpaste="return changeTextWord(this);" ondrag="javascript:return false;" style="border:1px solid #000000; height:100px;"></textarea>
<div class="editor_textexpand"><img src="images/common/bb_contract.gif" width="11" height="21" title="收縮編輯框" alt="收縮編輯框" onclick="resizeEditor(-20,'taAbObjective2')" /><img src="images/common/bb_expand.gif" width="11" height="21" title="擴展編輯框" alt="擴展編輯框" onclick="resizeEditor(20,'taAbObjective2')" /></div>

</form>
</body>
</html>