首页 > 编程语言 > 详细

JavaScript计算字符串中包含几个给定字符

时间:2017-07-12 09:53:11      阅读:275      评论:0      收藏:0      [点我收藏+]

原文发布时间为:2009-05-04 —— 来源于本人的百度文章 [由搬家工具导入]

下面以 逗号 为例子:

<html>
<head>
<title>
JavaScript计算字符串中包含几个给定字符
</title>
</head>
<body>
<script language="javascript">
function calculate()
{
//正则[^,]字符,是你需要统计的字符
document.all.result.value=document.all.uInput.value.replace(/[^,]/g, '').length;
}
</script>
请输入<input name="uInput" type="text" value="12,13,14,">
<input type="button" value="计算" onclick="calculate()"/>
结果为<input name="result" type="text">
</body>
</html>

JavaScript计算字符串中包含几个给定字符

原文:http://www.cnblogs.com/handboy/p/7153277.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!