Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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/javascript:表示子字符串的访问和更改的最短方式是什么?_Javascript_Jquery_Substring_Increment - Fatal编程技术网

jquery/javascript:表示子字符串的访问和更改的最短方式是什么?

jquery/javascript:表示子字符串的访问和更改的最短方式是什么?,javascript,jquery,substring,increment,Javascript,Jquery,Substring,Increment,可能重复: 我已经知道如何实现这个解决方案,但是有几行代码;我想知道是否有一种短而聪明的方法可以访问整数字符串的子字符串并将其递增,而子字符串不包含在任何标记标记中 /*Let's say the string is*/ "<span class="ideacount">[5 ideas]</span>" /*假设字符串为*/“[5个想法]” 我想增加它来表示“[6个想法]”类似的内容 var spanContent = $('#ideaCount').text()

可能重复:

我已经知道如何实现这个解决方案,但是有几行代码;我想知道是否有一种短而聪明的方法可以访问整数字符串的子字符串并将其递增,而子字符串不包含在任何标记标记中

/*Let's say the string is*/ "<span class="ideacount">[5 ideas]</span>"
/*假设字符串为*/“[5个想法]”
我想增加它来表示“[6个想法]”

类似的内容

var spanContent = $('#ideaCount').text();    
var i = parseInt(spanContent.replace(/[^0-9\.]+/g, ''));
i+=1;
$('#ideaCount').text( spanContent.replace(/[0-9\.]+/g, i+1) );

只需添加一些错误检查。

在发布之前,我真的应该想一想,因为我提出了一个单行解决方案(减去变量声明):$(this.html(“[”+((v=$(this.text()).match(/\d/)| | 0),+++v)+“idea”+(v>1?“s:“+”)”;除非有人能让它更瘦?