2016-07-11 5 views
0

app/views/reportsの下に_report_js.html.erbファイルという名前のjavascriptファイルがあります。私は自分のアプリケーションを実行すると、私はエラーを取得しています:

TypeError: $.url is not a function

これは私のコードです:

<script type="text/javascript"> 
    if($.url().param('ig') == 'true') { 
     alert("hi"); 
     $('#icons').hide(); 
     $('#photos').show(); 
    end 
</script> 
+0

を? – hjpotter92

+0

このようなプラグインはページに含まれていますか? '$ .url'はjQueryのコアメソッドではありません – charlietfl

答えて

2
$.url() 

はjQueryのコアの一部ではありません。あなたは似何かを達成したい場合は、おそらくそれを使用する

var getUrlParameter = function getUrlParameter(sParam) { 
    var sPageURL = decodeURIComponent(window.location.search.substring(1)), 
     sURLVariables = sPageURL.split('&'), 
     sParameterName, 
     i; 

    for (i = 0; i < sURLVariables.length; i++) { 
     sParameterName = sURLVariables[i].split('='); 

     if (sParameterName[0] === sParam) { 
      return sParameterName[1] === undefined ? true : sParameterName[1]; 
     } 
    } 
}; 

を使用します。

var tech = getUrlParameter('technology'); 

あなたの例では、それはこの

if(getUrlParameter('ig') == 'true') { 

source

0
//Just use this, no need to do loops: 
    var getUrlParameter = function getUrlParameter(sParam) { 
     var r = ""; 

     if (window.locaton.href.substring(window.locaton.href.indexOf(sParam + "="))) { 
      r = window.locaton.href.substring(window.locaton.href.indexOf(sParam + "=")(sParam + "=").length + 1); 
      // trim if there is other parameter on the list 
      if (r.indexOf("&") > 0) 
       r = r.substring(0, r.indexOf("&")); 
     } 
     // please do some simple test, I just wrote it without testing the code 
     return r; 
    } 
+1

これは答えをより便利にするため、コードのコンテキスト/説明を含める方が良いでしょう。 – EJoshuaS

0
のようなものを希望

コードライブラリー・プルライブラリーhttps://github.com/allmarkedup/purlがロードされているが、アクセスできないかアクセスできないと仮定している可能性があります。

あなたは別のアプローチみてください:それは、ライブラリ

if(purl().param('ig') == 'true') { 
関連する問題