<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>查询某个字符在字符串中出现的位置数组</title>
</head>
<body>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
qwbmcomqwbmqwbmcom<br />
qwbmcomqwbmqwbmcom<br />
查询 a
<script type="text/javascript">
$(function(){
var str = "qwbmcomqwbmqwbmcomqwbmcomqwbmqwbmcom";
var arr = [];
var pos = str.indexOf("o");
while(pos>-1){
arr.push(pos);
pos = str.indexOf("o",pos+1);
};
console.log(str);
console.log(arr);
});
</script>
</body>
</html>