JavaScript加载但不运行 - Wordpress

时间:2014-08-28 19:16:31

标签: javascript wordpress

我正在开发Wordpress主题,无法运行JavaScript。当我查看脚本加载的源代码并且文件路径正确时。

以下是加载脚本的functions.php代码:

function theme_js() {
    // Conditional scripts
    global $wp_scripts;

    wp_register_script( 'html5_shiv', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js',
    '', '', false );
    wp_register_script( 'respond_js', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js',
    '', '', false );

    $wp_scripts->add_data( 'html5_shiv', 'conditional', 'lt IE 9');
    $wp_scripts->add_data( 'respond_js', 'conditional', 'lt IE 9');
    // Footer scripts
    wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js',
    array('jquery'), null, true );
    wp_enqueue_script( 'color_js', get_template_directory_uri() . '/bootstrap/js/jquery.color.js',
    array('jquery'), null, true );
    wp_enqueue_script( 'header_js', get_template_directory_uri() . '/bootstrap/js/header.js',
    array('jquery'), null, true );
    wp_enqueue_script( 'rollover_js', get_template_directory_uri() . '/bootstrap/js/rollover.js',
    array('jquery'), null, true );
}
add_action ( 'wp_enqueue_scripts', 'theme_js' );

有人可以告诉我他们为什么不会参加比赛吗?

供参考 - header.js:

$(window).scroll(function () {

//After scrolling 300px from the top...
if ($(window).scrollTop() >= 300) {
    $(".navbar").stop().animate({backgroundColor: "#1e3b4e"}, 600);
    $(".navbar-nav > li > a").css("color", "#ffffff");
    $("#logo").attr("src", "img/logo.png");

//Otherwise remove inline styles and thereby revert to original stying
} else {
    $(".navbar").stop().animate({backgroundColor: "rgb(255, 255, 255, 1)"}, 400);
    $(".navbar-nav > li > a").css("color", "#1e3b4e");
    $("#logo").attr("src", "img/newlogo.png");
}

});

0 个答案:

没有答案