[英]Hiding Content Based on Content of URL String
I am trying to hide a certain fieldset with an id of "retail" based on if the URL has 'studio' as a part of it. 我试图根据URL是否包含“工作室”来隐藏ID为“零售”的某个字段集。 The URL would read as follows:
该URL如下所示:
/island-careers/studio/accounting/accountant/apply.html /island-careers/studio/accounting/accountant/apply.html
Here is my script I have written up but I can't seem to get it to recognize if 'studio' is in the URL. 这是我写的脚本,但似乎无法识别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>
The "console.log(split[4]); was to find the location of 'studio' in the array. There must be something wrong with my IF statement I guess. I also tried this method but it didn't work for me either: “ 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.