나는 다음과 같습니다.
if (referrer.indexOf("Ral") == -1) { ... }
왓 아이 라이크 랄 대소문자 무시 할 수 있도록 해야 할 것은 '', '랄 랄', ',' 등이 여전히 match).
'수' 는 것을 말할 수 있는 방법이 랄 구분하지 않습니다.
이후 추가 '네스토로르카스 ()' '조회인'. 이 방법은 문자열에서 돌리고 소문자 구체화하십시오. 그런 다음 "사용 '대신' 사용 '스이네쇼프 랄 랄 ()' '.
if (referrer.toLowerCase().indexOf("ral") === -1) {
같은 달성됩니다 정규식이 사용할 수도 있습니다 (때 유용합니다 어하여 테스트하려면 동적임 패턴):
if (!/Ral/i.test(referrer)) {
// ^i = Ignore case flag for RegExp
또 다른 옵션은 검색 방법에 따라 사용할 수 있다.
if (referrer.search(new RegExp("Ral", "i")) == -1) { ...
소문자로 변환 및 정보기술 (it) 보다 세련된 보입니다 다음 문자열 전체가 더 효율적일 수 있습니다. < br>; () '와' 코드 2 개를 한 번에 걸쳐 토로르카스 전달하십시오 켜있을 迈向 변환할지 전체 문자열을 string, 소문자 및 또 다른 이유는 필요한 찾으려면 index.< br>; 정규 표현식 '와' 코드 하나만 놓고, 필요한 일치시킵니다 index.< br> 워크플로가 문자열이어야 전달하십시오 보인다.
따라서 긴 문장열 사용할 수 있는 내가 추천하는 '정규 표현식' 버전 (아마 에서 이 파선-짧은 문장열 않했노라 RegExp 객체 생성 '효율성' 이 계정에 대해 표시되어도)
몇 가지 외곽진입 삽입하십시오.
스케쳐내 확인할지 그냥 이 경우, 다음과 같은 일을 진행하십시오 구분하지 않습니다.
if (referrer.toLowerCase().indexOf("Ral".toLowerCase()) == -1) {
...
대신에, 만약 이 검사를 수행하는 you& # 39, re 정기적으로 indexOf () '과 유사한 방법을 추가할 수 있습니다' String '새' 만들었지만, 이 경우 구분하지 않습니다.
String.prototype.indexOfInsensitive = function (s, b) {
return this.toLowerCase().indexOf(s.toLowerCase(), b);
}
// Then invoke it
if (referrer.indexOfInsensitive("Ral") == -1) { ...
Es2016 에서 조금 더 쉽게 사용할 수도 있습니다 / / 더욱 세련된 방법:
if (referrer.includes("Ral")) { ... }
또는
if (referrer.toLowerCase().includes(someString.toLowerCase())) { ... }
다음은 '일부' 와 '지의 크루즈 스이네쇼프 비교 () ()'. https://dev.to/adroitcoder/includes-vs-indexof-in-javascript
디자인 노트: 그래서 내가 하고 싶은 최소화하므로 메모리 사용량, 따라서 복사 / 억제하는 써줬지 의 속도 향상 꾨т 臾몄젣媛? 내가 solaris. V8 (및 기타 엔진) 이 기능을 최적화 수 있습니다.
//TODO: Performance testing
String.prototype.naturalIndexOf = function(needle) {
//TODO: guard conditions here
var haystack = this; //You can replace `haystack` for `this` below but I wan't to make the algorithm more readable for the answer
var needleIndex = 0;
var foundAt = 0;
for (var haystackIndex = 0; haystackIndex < haystack.length; haystackIndex++) {
var needleCode = needle.charCodeAt(needleIndex);
if (needleCode >= 65 && needleCode <= 90) needleCode += 32; //ToLower. I could have made this a function, but hopefully inline is faster and terser
var haystackCode = haystack.charCodeAt(haystackIndex);
if (haystackCode >= 65 && haystackCode <= 90) haystackCode += 32; //ToLower. I could have made this a function, but hopefully inline is faster and terser
//TODO: code to detect unicode characters and fallback to toLowerCase - when > 128?
//if (needleCode > 128 || haystackCode > 128) return haystack.toLocaleLowerCase().indexOf(needle.toLocaleLowerCase();
if (haystackCode !== needleCode)
{
foundAt = haystackIndex;
needleIndex = 0; //Start again
}
else
needleIndex++;
if (needleIndex == needle.length)
return foundAt;
}
return -1;
}
이유는 내 이름:
왜안돼요.:
다음 코드를 사용하여 보다 원활하게 수행하기 위한 검색
var myFav = "javascript";
var theList = "VB.NET, C#, PHP, Python, JavaScript, and Ruby";
// Check for matches with the plain vanilla indexOf() method:
alert( theList.indexOf( myFav ) );
// Now check for matches in lower-cased strings:
alert( theList.toLowerCase().indexOf( myFav.toLowerCase() ) );
첫 번째 경고 (), 자바스크립트 반환되었습니다 1" " -; - indexOf () 즉, a 매치 찾지 못했다. 이 때문에, 단지 " JavaScript". 첫 번째 문자열을 올바르게 대문자로 소문자보다) 는 두 번째. 대소문자를 검색을 수행할 수 있는 indexOf () 또는 소문자화 인컨텍스트 대문자화 문장열 모두 할 수 있습니다. 즉, 두 번째 경고를 같이 (), JavaScript 에서는 확인할지 문자열 찾고 있는 것은, 대 / 소문자 무시됨.
참조에는 http://freewebdesigntutorials.com/javaScriptTutorials/jsStringObject/indexOfMethod.htm
var originalText = $("#textContainer").html()
$("#search").on('keyup', function () {
$("#textContainer").html(originalText)
var text = $("#textContainer").html()
var val = $("#search").val()
if(val=="") return;
var matches = text.split(val)
for(var i=0;i<matches.length-1;i++) {
var ind = matches[i].indexOf(val)
var len = val.length
matches[i] = matches[i] + "<span class='selected'>" + val + "</span>"
}
$("#textContainer").html(matches.join(""))
<input type="text" id="search">
<div id="textContainer">
lorem ipsum is simply dummy text of the printing and typesetting industry. lorem ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of letraset sheets containing lorem ipsum passages, and more recently with desktop publishing software like Aldus pagemaker including versions of lorem ipsum.</div>
[고데펜] [1]
[1]: https://codepen.io/MichaelSel/pen/gmNGEX = 1111년 편집자?