繁体   English   中英

根据URL字符串的内容隐藏内容

[英]Hiding Content Based on Content of URL String

我试图根据URL是否包含“工作室”来隐藏ID为“零售”的某个字段集。 该URL如下所示:

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

这是我写的脚本,但似乎无法识别URL中是否包含“ studio”。

<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>

“ console.log(split [4]);是要在数组中查找'studio'的位置。我猜想我的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>

更改CSS的jQuery行应为:

 jQuery('#retail').css('display', 'none');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM