In javascript, how can I ignore the case sensitivity of indexOf? Replace all of them with uppercase or lowercase letters, and then compare them.
The first occurrence of a substring In the indexOf object.
Use toLowerCase or toUpperCase
Script var testStr = 'abcdef'; var subStr = 'bcd'; alert (testStr. toLowerCase (). indexOf (subStr. toLowerCase (); testStr = 'abcdef'; alert (testStr. toLowerCase (). indexOf (subStr. toLowerCase (); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it 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
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Look at me, compatible with the original indexOf <script language = "javascript">/* Author: A niu (NIU kunliang) QQ: 273352165 MSN: niukl@hotmail.com statement: Can Be Used for free, please keep this information. If you have made any changes, please remember to tell me! */String. prototype. _ indexOf = String. prototype. indexOf; String. prototype. indexOf = function () {if (typeof (arguments [arguments. length-1])! = 'Boolean') return this. _ indexOf. apply (this, arguments); else {var bi = arguments [arguments. length-1]; var thisObj = this; var idx = 0; if (typeof (arguments [arguments. length-2]) = 'number') {idx = arguments [arguments. length-2]; thisObj = this. substr (idx);} var re = new RegExp (arguments [0], bi? 'I': ''); var r = thisObj. match (re); return r = null? -1: r. index + idx ;}} alert ("bcssssasdfsdf ". indexOf ('A', 3, true); alert ("bcssssasdfsdf ". indexOf ('A', 3); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]