Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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-将逗号包装在a<;span>;?_Jquery - Fatal编程技术网

jQuery-将逗号包装在a<;span>;?

jQuery-将逗号包装在a<;span>;?,jquery,Jquery,我使用以下jQuery将元素中的每个字母包装成一个span: $('.num .stat').children().andSelf().contents().each(function() { if(this.nodeType == 3) { var $this = $(this); $this.replaceWith($this.text().replace(/(\w)/g, '<span class="s-$&">$&</span>

我使用以下jQuery将元素中的每个字母包装成一个span:

$('.num .stat').children().andSelf().contents().each(function() {
  if(this.nodeType == 3) {
    var $this = $(this);
    $this.replaceWith($this.text().replace(/(\w)/g, '<span class="s-$&">$&</span>'));
  }    
});
$('.num.stat').children()和self().contents().each(function()){
if(this.nodeType==3){
var$this=$(this);
$this.replaceWith($this.text().replace(/(\w)/g,$&');
}    
});
我将用这个包装数字。我遇到的问题是,当我的号码中有逗号(例如23000)时,逗号没有被包装

你知道我怎样才能把逗号也包装在
中吗


谢谢

逗号不在
\w
的子集中。您可以使用
来匹配所有字符:

$this.text().replace(/(.)/g, '<span class="s-$&">$&</span>')
$this.text().replace(/()/g,$&'))

逗号不在
\w
的子集中。您可以使用
来匹配所有字符:

$this.text().replace(/(.)/g, '<span class="s-$&">$&</span>')
$this.text().replace(/()/g,$&'))

\w不包括逗号,请尝试以下操作:/([\w\,])/g

\w不包括逗号,请尝试以下操作:/([\w\,])/g