Let me introduce to you how to make the indexOf function in JavaScript ignore case.
Change them all into uppercase or lowercase, and then compare.
This is a relatively simple method!
The character position where the substring appears for the first time in the indexOf object.
Use toLowerCase or toUpperCase as follows:
]
Or look at the following How to extend the indexof function:
If you need to introduce external Js, you need to refresh to execute
]
[Ctrl A select all Note: <script>
var testStr = 'ABCDEF';
var subStr = 'bcd';
alert(testStr.toLowerCase().indexOf(subStr.toLowerCase()));
testStr = 'AbCdEf';
alert(testStr.toLowerCase().indexOf(subStr.toLowerCase()));
</script>If you need to introduce external Js, you need to refresh to execute <script>
String.prototype.indexOf = function(f,m){
var mm = (m == false) ? "i":"";
var re = eval("/"+ f +"/"+mm);
var rt = this.match(re);
return (rt == null) ? -1:rt.index;
}
var test = "absnegKIugfkalg";
alert(test.indexOf("kiu",false));
</script>]
Statement: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