我想找到 $measurediv
中文本中包含的空白/空格的数量。感谢您对此提供的帮助。
<html>
<div id="welcomeMsgDiv" style="width:210px;">
<h2 style="font-family:Arial;font-size:17px;font-weight:bold">Welcome,
First Name Last Name!</h2>
</div>
<script type="text/javascript">
$origdiv = $('div#welcomeMsgDiv');
$measurediv = $origdiv.clone();
</script>
</html>
最佳答案
有很多方法可以做到这一点。例如(对于任何类型的空间):
var nbBlankSpaces = $measurediv.text().match(/\s/g).length
关于javascript - 如何计算 Div 中包含的字符串中的空格数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30581915/