Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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
Javascript jquery-拆分和计数字符?_Javascript_Jquery_Split - Fatal编程技术网

Javascript jquery-拆分和计数字符?

Javascript jquery-拆分和计数字符?,javascript,jquery,split,Javascript,Jquery,Split,我试图根据一个特定的字符分割一个字符串,然后计算每个部分中的字符数。有办法做到这一点吗 因此,我: html 你脑子里有太多jQuery了: var first = characters[0].length; var second = characters[1].length; 字符是字符串数组,而不是jQuery对象。字符串没有.text()方法,它们已经是文本了。只需访问它们的length属性即可 $(document).ready(function() { $('.splitMe'

我试图根据一个特定的字符分割一个字符串,然后计算每个部分中的字符数。有办法做到这一点吗

因此,我:

html
你脑子里有太多jQuery了:

var first = characters[0].length;
var second = characters[1].length;
字符
是字符串数组,而不是jQuery对象。字符串没有
.text()
方法,它们已经是文本了。只需访问它们的
length
属性即可

$(document).ready(function() {
   $('.splitMe').each(function() {
      var item = $(this).attr('title');
      var characters = item.split("|");

      // Here's where I get stuck... 
      // Tried various methods of length, but haven't been able to get it to work

      // Most recent version that failed miserably... 
      var first = characters[0].text().length;
      var second = characters[1].text().length;

      alert(first+" "+second); //Yields characters[0] is not a function
   });
});
var first = characters[0].length;
var second = characters[1].length;