例子:在str1中查找"P"<script language="javascript">
function IndexDemo(str2){
var str1 = "BABEBIBOBUPBABEBIBOBU"
if(str1.indexOf(str2)>-1)
{alert(str2+"存在!")}
}
IndexDemo("P");
</script>
function IndexDemo(str2){
var str1 = "BABEBIBOBUPBABEBIBOBU"
if(str1.indexOf(str2)>-1)
{alert(str2+"存在!")}
}
IndexDemo("P");
</script>
也可以用正则表达式的test函数比较起来Str.indexof简单一些