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

このコードをアクティブな選択メニューに使用します。jQueryでセレクタ条件でtoLowerCaseを使用する方法

私は、私はそれをどのように行うことができます。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

あなたはそれだけではJavaScriptオブジェクトの値の取り扱いですが、私は以下やっただけで同じよう小文字に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>

はそれが役に立てば幸い!

関連する問題