Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 计算所有人之间的字数<;strong>;divid中的元素_Jquery - Fatal编程技术网

Jquery 计算所有人之间的字数<;strong>;divid中的元素

Jquery 计算所有人之间的字数<;strong>;divid中的元素,jquery,Jquery,我数不出所有强元素中的所有单词。 我的例子 Hir是10个单词 这里有8个单词和35个字符 但是我的剧本告诉我我有9个 如果你有任何建议,那就好了。 $(函数(){ 变量文本,charsLength=0,WordScont=0; $('#strongdiv strong')。每个(函数(){ text=$.trim($(this.text()); charsLength+=text.length; wordsCount+=text.split(/\s+/).length; }); $(“#输出”

我数不出所有强元素中的所有单词。 我的例子

Hir是10个单词 这里有8个单词和35个字符

但是我的剧本告诉我我有9个

如果你有任何建议,那就好了。

$(函数(){
变量文本,charsLength=0,WordScont=0;
$('#strongdiv strong')。每个(函数(){
text=$.trim($(this.text());
charsLength+=text.length;
wordsCount+=text.split(/\s+/).length;
});
$(“#输出”).append(“单词”+wordscont+”
字符:“+charsllength”); });
Post您的脚本(fiddle),我们将更容易提供帮助。查看您的控制台:
uncaughttypeerror:Object我们这里有8个单词和35个字符sasd sa没有方法“html”
这不是唯一的问题:)
$(function() {
  var text = $.trim($('#strongdiv strong').text());
  var charsLength = text.length;
  var wordsCount = text.html().split(/\s+/).length;
  alert(wordsCount);
});
$(function() {
  var text, charsLength=0,wordsCount=0;
  $('#strongdiv strong').each(function() {
    text = $.trim($(this).text());
    charsLength += text.length;
    wordsCount += text.split(/\s+/).length;
  });
  $("#output").append("words"+wordsCount+"<br/>chars: "+charsLength);
});