基于URL字符串内容隐藏内容

时间:2014-07-02 15:58:38

标签: javascript jquery html css

我正在尝试隐藏ID为"零售"的某个字段集。根据网址是否包含' studio'作为其中的一部分。 URL的内容如下:

/island-careers/studio/accounting/accountant/apply.html

这是我写的剧本,但我似乎无法识别是否' studio'在URL中。

<script>
    jQuery(document).ready(function(){

        var path = window.location.pathname;

        console.log(path);

        var split = window.location.href.split('/');

        console.log(split);

        console.log(split[4]);

      if (split[4] === 'studio') {
          jQuery('#retail').css('display, none');
      }  
    });
</script>

&#34; console.log(split [4]);是找工作室的位置&#39;在数组中。我想我的IF语句一定有问题。我也试过这种方法,但它对我来说也不起作用:

<script>
    jQuery(document).ready(function(){

        var path = window.location.pathname;

        console.log(path);


      if (path.indexOf('studio') >= 0) {
          jQuery('#retail').css('display, none')
      }  
    });
</script>

1 个答案:

答案 0 :(得分:4)

更改CSS的jQuery行应该是:

 jQuery('#retail').css('display', 'none');
相关问题