Home > Web Front-end > JS Tutorial > body text

jquery indexOf usage method_jquery

WBOY
Release: 2016-05-16 17:25:05
Original
1409 people have browsed it

indexOf() and lastIndexOf() are js usages and have nothing to do with jquery. You can just use native js directly.

The indexOf() and lastIndexOf() methods return the position of the specified substring in another string. If the substring is not found, -1 is returned.
The difference between these two methods is that the indexOf() method starts to retrieve the string from the beginning of the string (position 0), while the lastIndexOf() method starts to retrieve the substring from the end of the string.

strObj.indexOf(subString[, startIndex]) Parameter strObj is required. String object or literal. subString is required. The substring to be found in the String object. starIndex optional. This integer value indicates the index within the String object at which to begin the search. If omitted, the search is from the beginning of the string.

Description The indexOf method returns an integer value indicating the starting position of the substring within the String object. If the substring is not found, -1 is returned. If startindex is negative, startindex is treated as zero. If it is greater than the largest character position index, it is treated as the largest possible index. The search is performed from left to right. Otherwise, the method is the same as lastIndexOf.

Example: [CODE_HTML] [/CODE_HTML] The final result is -1,0,3

if(ss.indexOf('winner')>-1)
strobj.indexOf(substring[, startindex])
where strobj is a required option. string object or text

Copy code The code is as follows:


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template