字数统计框javascript/php

编程入门 行业动态 更新时间:2024-10-21 16:26:55
本文介绍了字数统计框javascript/php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在文本框中实现单词计数器.我正在使用以下链接:

I am trying to implement a word counter in textbox. I am using the links below:

JS小提琴 第二个链接

<textarea name="myMessage" onkeyup="wordcount(this.value)"></textarea> <script type=""text/javascript""> var cnt; function wordcount(count) { var words = count.split(/\s/); cnt = words.length; var ele = document.getElementById('w_count'); ele.value = cnt; } document.write("<input type=text id=w_count size=4 readonly>"); </script>

文字计数器工作正常.但是我的情况如下:

Word counter is working fine. But my scenario is like as below:

  • 对于最合适的匹配项"一词,如果用户键入缩写形式为""MSM" ",则MSM也应计为3个单词.
  • 以同样的方式,如果有大学名称,例如"DAV",则也应计为3个单词.
  • for word "Most Suitable Match" if user type short form as "MSM" then MSM also shall be counted as 3 words.
  • In the same way if there is name of college like "DAV" then it shall also be counted as 3 words.
  • 请提出建议!

    推荐答案

    我有一个简单的功能:

    var regex = [/DAV/g, /MAC/g]; function countWords() { var count = []; regex.forEach(function(reg) { var m = text.match(reg); if (m) { count = count.concat(m); } }); // the number of known acronym wrote in the text var acronyms = count.length; // how much words generated from an acronym (e.g. DAV === 3 words; AB === 2 words and so on) var wordsFromAcronyms = count.join().replace(/,/g,'').length; // how many words wrote (this is equal to your code) var rawWords = text.match(/\S+/g).length; // compute the real number return rawWords - acronyms + wordsFromAcronyms; }

    计算首字母缩写词的数量(已知首字母缩写词的列表存储在regex数组中),然后计算首字母缩写词(wordsFromAcronym)生成多少个单词,然后减去首字母缩写词的数量(rawWords)中的(acronyms),然后加上wordsFromAcronym.

    It counts the number of the wrote acronym (the list of the known acronyms is stored in regex array), then count how much words are generated by the acronyms (wordsFromAcronym), and then substract the number of acronyms (acronyms) from the total words (rawWords) and then add the wordsFromAcronym.

    这里是 PLNKR .

    更多推荐

    字数统计框javascript/php

    本文发布于:2023-11-11 07:08:33,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1577727.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:字数   javascript   php

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!