Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 修改和扩展工作jquery脚本_Javascript_Jquery - Fatal编程技术网

Javascript 修改和扩展工作jquery脚本

Javascript 修改和扩展工作jquery脚本,javascript,jquery,Javascript,Jquery,我有一个工作脚本: <script> jQuery( document ).ready(function() { console.log( "ready!" ); var hideUrl=[ 'https://www.gustotosto.it/shop/boni/', 'https://www.gustotosto.it/shop/agropic/', ]; if(hideUrl.indexOf(window.location.href)>=0){

我有一个工作脚本:

<script>
jQuery( document ).ready(function() {
    console.log( "ready!" );
var hideUrl=[
'https://www.gustotosto.it/shop/boni/',
'https://www.gustotosto.it/shop/agropic/',
];
if(hideUrl.indexOf(window.location.href)>=0){
    jQuery('.title-shop').hide();
}

});
</script>

jQuery(文档).ready(函数(){
console.log(“准备就绪!”);
瓦希杜尔=[
'https://www.gustotosto.it/shop/boni/',
'https://www.gustotosto.it/shop/agropic/',
];
if(hideUrl.indexOf(window.location.href)>=0){
jQuery('.title shop').hide();
}
});
现在我想修改它,因为它只是隐藏了var中列出的url的“.title shop”;我想扩展它并隐藏“.title shop”,如果url包含var hideUrl,则包括子页面。 我这样修改了它,但它不工作。怎么了?有人能帮我吗

<script>
jQuery( document ).ready(function() {
    console.log( "ready!" );
var hideUrl=[
'https://www.gustotosto.it/shop/boni/',
'https://www.gustotosto.it/shop/agropic/',
];
if (window.location.href.indexOf("hideUrl") > -1){
    jQuery('.title-shop').hide();
}
});
</script>

jQuery(文档).ready(函数(){
console.log(“准备就绪!”);
瓦希杜尔=[
'https://www.gustotosto.it/shop/boni/',
'https://www.gustotosto.it/shop/agropic/',
];
if(window.location.href.indexOf(“hideUrl”)>-1){
jQuery('.title shop').hide();
}
});

您的代码中有两个问题。首先,
hideUrl
是一个变量名,所以不应该用引号括起来。这样做将意味着它被视为字符串文本

其次,您需要遍历
hideUrl
数组中的所有项,并分别比较它们。试试这个:

jQuery($=>{
变量hideUrls=[
'https://www.gustotosto.it/shop/boni/',
'https://www.gustotosto.it/shop/agropic/'
];
forEach(url=>{
if(window.location.href.indexOf(url)>-1){
$('.title shop').hide();
}
});
});

非常感谢您!它工作得很好。我自己永远也做不到