jQuery(window).load(function($) 仍然给出 Uncaught TypeError: $ is not a function

use*_*976 0 javascript wordpress jquery

我在我的 Wordpress 站点中使用 jquery 时遇到问题。阅读此线程后,我以为我能够解决我的问题,但事实并非如此。

这是我尝试过的,但我仍然收到类型错误:

jQuery(window).load(function($)
{
    // auto panning
    PanPicture = function () {
        $(".wrap").show();
        $(".wrap").children("#panimg").show();
        $(".wrap").children("#panimg").animate({
            "left": "-800px"
        }, 20000);
        $(".wrap").children("#panimg").animate({
            "left": "0px"
        }, 20000);
        // refill the animation queue after animations done
        $(".wrap").children("#panimg").queue(

        function () {
            PanPicture();
            $(".wrap").children("#panimg").dequeue();
        });
    };
    //setTimeout( function() { PanPicture(); }, 1000 );
    //$(".wrap").children("#panimg").load(function() { PanPicture(); });
    PanPicture();
});
Run Code Online (Sandbox Code Playgroud)

控制台给了我这个:

Uncaught TypeError: $ is not a function
PanPicture @ jd_autopan.js?ver=4.4.2:5
(anonymous function) @ jd_autopan.js?ver=4.4.2:23
m.event.dispatch @ jquery.js?ver=1.11.3:4r.handle @ jquery.js?ver=1.11.3:4
Run Code Online (Sandbox Code Playgroud)

Igo*_*ych 5

试试这个并确保你的脚本jquery之后加载(如果你使用wp_enqueue_script添加你的脚本,array('jquery')作为第三个参数传递)

jQuery(document).ready(
function ($)
{
    //blah blah
});
Run Code Online (Sandbox Code Playgroud)