2017-01-09 11 views
-6
var path = window.location.pathname; // Returns path only 
var element = jq_menu("#topMenu a[href='" + path + "']"); 
element.parent().closest('li').addClass('active'); 

이 코드를 선택 메뉴에 사용합니다.선택기 조건에서 toLowerCase를 사용하는 방법 jQuery에서

나는

내가 어떻게 할 수 있습니다

2 줄에서 lowerCasehref 값을 변환하려면?

+0

'path'는 문자열입니다. 그래서 ...'path.toLowerCase()'O.o – Andreas

+0

'path.toLowerCase()'를 시도해 보셨습니까? – Rajesh

+0

이것은 적절한 질문으로 여겨지지 않습니다. 사람들이 계속 그런 질문을한다면 그것은 수조조 이상의 질문이 될 것입니다. 'toLowerCase()'함수를 사용하지 않았습니까? –

답변

-2

경로가 문자열이기 때문에 대신;을 사용하십시오.

var path = window.location.pathname; // Returns path only 
var element = jq_menu("#topMenu a[href='" + path.toLowerCase() + "']"); 
element.parent().closest('li').addClass('active'); 
+0

href 값을 LowerCase로 변환하고 싶습니다. –

+1

다른 답변에 대한 의견을 읽어보십시오. 또한이 문제는 문제의 주석에서 언급되었으므로 추가 할 항목을 추가하지 않으면 필요가 없습니다. – Rajesh

+0

나는 아래쪽으로'href'를 비교하고, 아래쪽에'path'를 넣고 그 원소를 돌려 주길 원한다. –

0

아래와 같이 href 값을 소문자로 변환 할 수 있습니다. 단지 자바 스크립트 객체 값 처리입니다. 당신은 그것을 실행할 수 있습니다

// All is happening on load, just for example 
 
$(document).ready(function() { 
 
    // Before 
 
    console.log($('a#my-selector').attr('href')); 
 
    // Getting value and converting 
 
    var value = $('a#my-selector').attr('href').toLowerCase(); 
 

 
    // ..you can use it where you want now.. 
 

 
    // I'm just setting it back to the element.. 
 
    $('a#my-selector').attr('href', value); 
 
    // After 
 
    console.log($('a#my-selector').attr('href')); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<a id="my-selector" href="LINK-UPPER-CASE">I'm uppercase</a>

는 희망이 도움이!