是否可以使用jQuery从pararaph中获取相同的字母数?所以让我说我有这个段落:
<div>like this printer</div>
Run Code Online (Sandbox Code Playgroud)
我想获得"i"的字符数,这意味着我应该得到3,因为有3个"我".我在考虑使用$(div:contains(i)),但现在确定如何实现它.有什么建议?非常感谢!
//Your string
var str = "I like this printer";
//Shows the count of "i" in your string.
console.log(str.replace(/[^i]/g, "").length);
Run Code Online (Sandbox Code Playgroud)
快乐的编码!
| 归档时间: |
|
| 查看次数: |
126 次 |
| 最近记录: |