IndexOf () and LastIndexOf () is the use of JS, and jquery is irrelevant, all directly with the original JS can be.
The IndexOf () and LastIndexOf () methods return the position of the specified substring in another string, or 1 if no substring is found.
The difference between the two methods is that the IndexOf () method retrieves the string starting at the beginning of the string (position 0), and the LastIndexOf () method retrieves the substring starting at the end of the string.
Strobj.indexof (substring[, StartIndex]) parameter strobj required option. A String object or text. subString required option. The substring to find in the string object. Starindex can be selected. An integer value that indicates the index in which to start the lookup within a String object. If omitted, it is looked up from the beginning of the string.
Explains that the IndexOf method returns an integer value that indicates the start position of the substring of a string object. If no substring is found, returns-1. If the startindex is a negative number, the startindex is treated as zero. If it is larger than the maximum character position index, it is considered to be the largest possible index. Performs a lookup 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 code as follows:
<script type= "Text/javascript" >
array.prototype.indexOf = function (str) {
for (var i = 0; i < this.length; i++) {
if (str = = This[i]) {
return i;
}
}
return-1;
}
</script>