Heim  >  Artikel  >  Web-Frontend  >  jquery indexOf使用方法_jquery

jquery indexOf使用方法_jquery

WBOY
WBOYOriginal
2016-05-16 17:25:051384Durchsuche

indexOf() 和 lastIndexOf() 是js的用法,与jquery是无关的,所有直接用原生js就可以了。

indexOf() 和 lastIndexOf() 方法返回的都是指定的子串在另一个字符串中的位置,如果没有找不到子串,则返回 -1。
这两个方法的不同之处在于,indexOf() 方法是从字符串的开头(位置 0)开始检索字符串,而 lastIndexOf() 方法则是从字符串的结尾开始检索子串。

strObj.indexOf(subString[, startIndex]) 参 数 strObj 必选项。String 对象或文字。 subString 必选项。要在 String 对象中查找的子字符 串。 starIndex 可选项。该整数值指出在 String 对象内开始查找的索引。如果省略,则从字符串的开始处查找。

说明 indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置。如果没有找到子字符串,则返回 -1。 如果 startindex 是负数,则 startindex 被当作零。如果它比最大的字符位置索引还大,则它被当作最大的可能索引。 从左向右执行查找。否则,该方法与 lastIndexOf 相同。

例子: [CODE_HTML] [/CODE_HTML] 最后得到的结果是-1,0,3

if(ss.indexOf('winner')>-1)
strobj.indexOf(substring[, startindex])
其中strobj是必选项。string 对象或文字

复制代码 代码如下:


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn