http://tool.lanrentuku.com/zishutongji/ <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" type="text/css" href="http://tool.lanrentuku.com/img/tool.css"> </head> <script src="http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script> <body> <!-- /工具开始 --> <style type="text/css"> .num{ font-size:14px; font-weight:700; color:#F00} </style> <h3>这是一个快速计算字数和字符数的小工具(小说作者和或编辑必备工具):</h3> <textarea id="content" name="content" class="toolarea"> 在线字数统计 工欲善其事,必先利其器。 显而易见,最高的效率就是对现有材料的最佳利用。学会偷懒,并懒出境界是提高工作效率最有效的方法! 懒人图库 http://www.lanrentuku.com/ 2016</textarea> 汉字:<span id="zhongwen" class="num">0</span> 个<br /> 中文标点:<span id="zbiaodian" class="num">0</span> 个<br>汉字+标点:<span id="zhongwenbiaodian" class="num">0</span> 个<br /> 英文:<span id="yingwen" class="num">0</span> 个 (含英文状态下的数字、符号、标点)<br> 数字:<span id="shuzi" class="num">0</span> 个<br /> 字符总数:<span id="numwords" class="num">0</span> 个字符<br /><br /> 小贴士:汉字和中文标点算两个字符,数字、空格、英文字母,英文标点算做一个字符。<br /> <script language="javascript"> function $(id){return document.getElementById(id);} var EventUtil = function(){}; EventUtil.addEventHandler = function(obj,EventType,Handler) { //如果是FF if(obj.addEventListener) { obj.addEventListener(EventType,Handler,false); } //如果是IE else if(obj.attachEvent) { obj.attachEvent('on'+EventType,Handler); } else { obj['on'+EventType] = Handler; } } //alert($("chaptercontent").value); if($("content")){ EventUtil.addEventHandler($('content'),'propertychange',CountChineseCharacters); EventUtil.addEventHandler($('content'),'input',CountChineseCharacters); //EventUtil.addEventHandler($('chaptercontent'),'keydown',CountChineseCharacters('chaptercontent')); } window.onload=CountChineseCharacters(); function showit(Word){ alert(Word); } function CountChineseCharacters() { Words=$('content').value; var W = new Object(); var Result = new Array(); var iNumwords = 0; var sNumwords = 0; var sTotal = 0;//双字节字符; var iTotal = 0;//中文字符; var eTotal = 0;//E文字符 var otherTotal = 0; var bTotal = 0; var inum = 0; for (i=0; i<Words.length; i++) { var c = Words.charAt(i); if (c.match(/[\u4e00-\u9fa5]/)) { if (isNaN(W[c])) { iNumwords++; W[c] = 1; } iTotal++; } } for (i=0; i<Words.length; i++) { var c = Words.charAt(i); if (c.match(/[^\x00-\xff]/)) { if (isNaN(W[c])) { sNumwords++; } sTotal++; } else { eTotal++; } if (c.match(/[0-9]/)) { inum++; } } //alert(iTotal); $('zhongwen').innerText=iTotal; $('zbiaodian').innerText=sTotal-iTotal; $('zhongwenbiaodian').innerText=sTotal; $('yingwen').innerText=eTotal; $('shuzi').innerText=inum; document.getElementById("numwords").innerHTML=iTotal*2+(sTotal-iTotal)*2+eTotal; } </script> <!-- /工具结束 --> </body> </html> 提示:你可以先修改部分代码再运行。 转载请注明:有爱前端 » 在线字数统计工具 喜欢 (0)or分享 (0)