Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.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添加到Wordpress头部_Javascript_Jquery_Wordpress - Fatal编程技术网

Javascript 将jQuery添加到Wordpress头部

Javascript 将jQuery添加到Wordpress头部,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我正在尝试向wordpress站点上的页面添加一些自定义jQuery 我使用了一个插件,允许我将代码直接插入特定页面的head.php文件中,但代码没有运行,我只是得到了错误 TypeError:$不是函数 $(文档).ready(函数(){ 我在回答这个问题时使用了jQuery(函数($){…: jQuery(函数($(文档).ready(函数(){ jQuery(函数($)(“#a”).mouseover(函数(){ jQuery(function($)(“#b”).css(“背景图像”,

我正在尝试向wordpress站点上的页面添加一些自定义jQuery

我使用了一个插件,允许我将代码直接插入特定页面的head.php文件中,但代码没有运行,我只是得到了错误

TypeError:$不是函数

$(文档).ready(函数(){

我在回答这个问题时使用了
jQuery(函数($){…


jQuery(函数($(文档).ready(函数(){
jQuery(函数($)(“#a”).mouseover(函数(){
jQuery(function($)(“#b”).css(“背景图像”,“url($)”)https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-black-cropped.jpg')");
});
jQuery(函数($)(“#a1”).mouseover(函数(){
jQuery(function($)(“#b”).css(“背景图像”,“url($)”)https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-blue-cropped.jpg')");
});
jQuery(函数($)(“#a2”).mouseover(函数(){
jQuery(function($)(“#b”).css(“背景图像”,“url($)”)https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-wash-cropped.jpg')");
});
jQuery(函数($)(“#slim-a”).mouseover(函数(){
jQuery(function($)(“#slim-b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/black-slim-rollover-cropped.jpg')");
});
jQuery(函数($)(“#slim-a1”).mouseover(函数(){
jQuery(function($)(“#slim-b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/blue-slim-rollover-cropped.jpg')");
});
jQuery(函数($)(“#slim-a2”).mouseover(函数(){
jQuery(function($)(“#slim-b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/blue-washed-slim-rollover-cropped.jpg')");
});
});
我想我的语法弄错了,但我不知道在哪里

我还尝试通过CDN在代码中链接jQuery,但这阻止了页面上其他来自插件的jQuery元素的工作,比如导航栏


如果有人知道我做错了什么以及如何解决这个问题,我将非常感谢您的帮助!

当我运行此代码时,它抛出:

未捕获的语法错误:意外标记(


…是一个语法错误

您使用
$
作为参数名,并在函数内部使用作为变量。您跳过了使用
{
}
创建函数体的位,以及将函数名(
$
)放在
(参数)
前面的位

您正在寻找的语法是(我将其拆分为清晰的命名函数,而不是内联所有内容)

…或所有内容都内联的版本:

jQuery(function ($) {
    $("#a").on("mouseover", function (event) {
        // Code to run on mouseover
    });

    // Put other calls to `$` here. Don't create additional `jQuery(readyEventHandler)`s!
});

脚本中存在语法错误,请尝试运行此脚本

<script>
    jQuery(document).ready(function(){
         jQuery("#a").mouseover(function(){
             jQuery("#b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-black-cropped.jpg')");
         });

    jQuery("#a1").mouseover(function(){
            jQuery("#b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-blue-cropped.jpg')");
         });

    jQuery("#a2").mouseover(function(){
             jQuery("#b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-wash-cropped.jpg')");
         });

    jQuery("#slim-a").mouseover(function(){
             jQuery("#slim-b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/black-slim-rollover-cropped.jpg')");
         });

     jQuery("#slim-a1").mouseover(function(){
             jQuery("#slim-b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/blue-slim-rollover-cropped.jpg')");
         });

    jQuery("#slim-a2").mouseover(function(){
             jQuery("#slim-b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/blue-washed-slim-rollover-cropped.jpg')");
         });

    });
</script>

jQuery(文档).ready(函数(){
jQuery(“#a”).mouseover(函数(){
jQuery(“#b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-black-cropped.jpg')");
});
jQuery(“#a1”).mouseover(函数(){
jQuery(“#b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-blue-cropped.jpg')");
});
jQuery(“#a2”).mouseover(函数(){
jQuery(“#b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-wash-cropped.jpg')");
});
jQuery(“#slim-a”).mouseover(函数(){
jQuery(“#slim-b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/black-slim-rollover-cropped.jpg')");
});
jQuery(“#slim-a1”).mouseover(函数(){
jQuery(“#slim-b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/blue-slim-rollover-cropped.jpg')");
});
jQuery(“#slim-a2”).mouseover(函数(){
jQuery(“#slim-b”).css(“背景图像”,“url”()https://oxfordriderwear.com/wp-content/uploads/2019/07/blue-washed-slim-rollover-cropped.jpg')");
});
});
function readyEventHandler ($) {
    // Inside this function `$` is whatever is passed as the first argument

    function mouseoverEventHandler(event) {
          // Code to run on mouseover
    }

    const element = $("#a");
    element.on("mouseover", mouseoverEventHandler);
}

jQuery(mouseoverEventHandler); // When the DOM is ready, this will call mouseoverEventHandler and pass the jQuery object in as the first argument
jQuery(function ($) {
    $("#a").on("mouseover", function (event) {
        // Code to run on mouseover
    });

    // Put other calls to `$` here. Don't create additional `jQuery(readyEventHandler)`s!
});
<script>
    jQuery(document).ready(function(){
         jQuery("#a").mouseover(function(){
             jQuery("#b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-black-cropped.jpg')");
         });

    jQuery("#a1").mouseover(function(){
            jQuery("#b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-blue-cropped.jpg')");
         });

    jQuery("#a2").mouseover(function(){
             jQuery("#b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/straight-wash-cropped.jpg')");
         });

    jQuery("#slim-a").mouseover(function(){
             jQuery("#slim-b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/black-slim-rollover-cropped.jpg')");
         });

     jQuery("#slim-a1").mouseover(function(){
             jQuery("#slim-b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/blue-slim-rollover-cropped.jpg')");
         });

    jQuery("#slim-a2").mouseover(function(){
             jQuery("#slim-b").css("background-image", "url('https://oxfordriderwear.com/wp-content/uploads/2019/07/blue-washed-slim-rollover-cropped.jpg')");
         });

    });
</script>