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

Hiding Content Based on Content of URL String

本文关键字:隐藏 URL 字符串 基于      更新时间:2023-09-26

我试图隐藏一个特定的字段集与"零售"基于如果URL有'工作室'作为它的一部分的id。URL的内容如下:

/island-careers/工作室/会计/会计/apply.html

这是我的脚本,我已经写了,但我似乎不能让它识别如果'工作室'是在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>

"console.log(分裂[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');