香烟 发表于 2007-4-27 10:15:46

***计数转换***单词及字符的统计脚本

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
要完成此效果需要两个步骤

第一步:把如下代码加入到<head>区域中

<script language="javascript">
<!-- begin
function countwords (this_field, alertwords, alertchars) {
if (alertwords == null) {
alertwords = true;
}
if (alertchars == null) {
alertchars = false;
}
var fullstr = this_field.value;
var charcount = fullstr.length;
var rexp = /[^a-za-z0-9]/gi;
var spacesstr = fullstr.replace(rexp, " ");
var cleanedstr = spacesstr + " ";
do {
var old_str = cleanedstr;
cleanedstr = cleanedstr.replace("", " ");
} while(old_str != cleanedstr);
var splitstring = cleanedstr.split(" ");
var wordcount = splitstring.length -1;

if (fullstr.length <1) {
wordcount = 0;
}
if (wordcount == 1) {
wordorwords = " 个单词";
}
else {
wordorwords = " 个单词";
}
if (charcount == 1) {
charorchars = " 个字符";
} else {
charorchars = " 个字符";
}
if (alertwords & alertchars) {
alert ("统计结果:\n" + "    " + wordcount + wordorwords + "\n" + "    " + charcount + charorchars);
}
else {
if (alertwords) {
alert ("word count:" + wordcount + wordorwords);
}
else {
if (alertchars) {
alert ("character count:" + charcount + charorchars);
      }
   }
}
return wordcount;
}
//end -->
</script>

第二步:把如下代码加入到<body>区域中

<form>
<textarea cols=40 rows=5 name=x>


      










-------- ------ ---- ------- -------------

http://www. huoyue. com.cn 活跃网,活跃人群的论坛,访问活跃网,将 给您 带来意想不到的收获,还可以 免费为您开论坛,让您免费拥有与朋友、 网友交流的论 坛。 你是年轻人吗? 你活跃你就上!
页: [1]
查看完整版本: ***计数转换***单词及字符的统计脚本