JS IndexOf方法
转自:http://hi.baidu.com/pao8041/blog/item/7b8d812f7d8e053a1e30891f.html
返回 String 对象内第一次出现子字符串的字符位置。
strObj.indexOf(subString[, startIndex])
参数
strObj
必选项。String 对象或文字。
subString
必选项。要在 String 对象中查找的子字符串。
starIndex
可选项。该整数值指出在 String 对象内开始查找的索引。如果省略,则从字符串的开始处查找。
说明
indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置。如果没有找到子字符串,则返回 -1。
如果 startindex 是负数,则 startindex 被当作零。如果它比最大的字符位置索引还大,则它被当作最大的可能索引。
从左向右执行查找。否则,该方法与 lastIndexOf 相同。
示例
下面的示例说明了 indexOf 方法的用法。
function IndexDemo(str2){
var str1 = "BABEBIBOBUBABEBIBOBU"
var s = str1.indexOf(str2);
return(s);
}
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利
This posting is provided "AS IS" with no warranties, and confers no rights.
This posting is provided "AS IS" with no warranties, and confers no rights.
浙公网安备 33010602011771号