2011-04-06 3 views
0

프로젝트에 대한 키워드 검색을 만들고 있습니다. 그래서 그것이 대소 문자를 구분하지 않도록하기 위해 비교 값을 만들기 전에 검색 값과 내용을 소문자로 설정합니다. self.contentSelected = jQuery('.policies_container .lof-element .lof-inner a').html();div의 내용을 소문자로 설정하십시오.

jQuery('.policies_container .lof-element .lof-inner a :contains("' + self.term + '")').each(function() { 
        jQuery(this).html(jQuery(this).html().replace(new RegExp(self.term, 'g'), '<span class="highlight">' + self.term + '</span>')); 
        jQuery(this) 
         .find('.highlight') 
         .fadeIn(self.fadeSpeed); 

        jQuery(".highlight").each(function() { 
         if(jQuery(this).parent().is(":hidden")) { 
          jQuery(this).closest(".lof-element").slideDown(); 
          jQuery(this).closest(".lof-toggler").addClass("active_acc"); 

          self.targetOffset = jQuery(".highlight:first-child").offset().top; 
          jQuery('html, body').animate({scrollTop: self.targetOffset}, self.scrollSpeed); 
         } 
        }); 
       }); 

여전히를 적용하는 동안 소문자로 그래서이 두 번째 여기에 라인

jQuery('.policies_container .lof-element .lof-inner a :contains("' + self.term + '")').each(function() { 내가 그 자체가 .lof - 내부 콘텐츠에 필요한 구문을 찾고 있어요 : 나는에있어 곳이다 : 선택자를 포함합니다.

도움, 고마워요!

답변

6

CSS의 속성 사용

text-transform:lowercase; 

또는 자바 스크립트 기능을 사용하면 두 소스를 변환하고 contains()에 전달하기 전에 소문자로 표현을 검색 할 필요가

variable.toLowerCase(); 

초 방법 (자바 스크립트)에서를 방법.

+0

'텍스트 transform' 자바 스크립트가 액세스하는 텍스트 노드에 영향을 미치지 않습니다. – alex

1

:contains()은 대소 문자를 구분합니다.

당신은 정규식을 사용할 수

filter() 지원하기 위해 ...

elements.filter(function() { 
    return $(this).text().match(/\bword\b/i); 
}); 
+0

헤이 감사합니다 알렉스, 약간의 수사 이후 나 자신이 어떻게가는 길인지를 발견했다. S –

+0

@Shane 엘리먼트 집합을 this로 전달하면 텍스트 노드에 'word'가 포함 된 요소를 반환합니다 (한 단어로 분리됨). 경계). – alex

관련 문제