你好我正在使用indexOf方法來搜索一個字符串是否存在於另一個字符串中。但我想要獲取字符串的所有位置?有沒有任何方法來獲取字符串存在的所有位置?在字符串中搜索字符串的所有實例
<html>
<head>
<script type="text/javascript">
function clik()
{
var x='hit';
//document.getElementById('hideme').value ='';
document.getElementById('hideme').value += x;
alert(document.getElementById('hideme').value);
}
function getIndex()
{
var z =document.getElementById('hideme').value;
alert(z.indexOf('hit'));
}
</script>
</head>
<body>
<input type='hidden' id='hideme' value=""/>
<input type='button' id='butt1' value="click click" onClick="clik()"/>
<input type='button' id='butt2' value="clck clck" onClick="getIndex()"/>
</body>
</html>
有沒有一種方法來獲得所有職位?
我很容易忘記匹配對象具有「索引」屬性! – Pointy 2010-07-29 19:03:41
非常感謝!正則表達式做了詭計! – sai 2010-07-29 19:04:04