Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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应用于Wordpress。你能帮助我吗?_Javascript_Jquery_Wordpress - Fatal编程技术网

我无法将javascript应用于Wordpress。你能帮助我吗?

我无法将javascript应用于Wordpress。你能帮助我吗?,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我在以下位置学习了本教程: 下面解释如何将javascript添加到wordpress。但是当我启动页面时,在sourcepage中,.js文件被重新定位到其他地方 我将.js文件放在“C:\Users\xxxxx\Documents\Websites\www.testsite.dev.cc\wp content\themes\profile lite\js”中,但在页面源代码中,该文件列在“”中 我尝试在“C:\Users\xxxxx\Documents\Websites\www.testsi

我在以下位置学习了本教程: 下面解释如何将javascript添加到wordpress。但是当我启动页面时,在sourcepage中,.js文件被重新定位到其他地方

我将.js文件放在“C:\Users\xxxxx\Documents\Websites\www.testsite.dev.cc\wp content\themes\profile lite\js”中,但在页面源代码中,该文件列在“”中

我尝试在“C:\Users\xxxxx\Documents\Websites\www.testsite.dev.cc\wp content\themes\profile lite”中创建一个文件夹,文件夹名为“style.cssjs”,以查看该文件是否可以读取,但没有任何运气

在my function.php文件中,以下是我的代码:

function cool_scripts(){

    wp_enqueue_script('cool-stuff', get_stylesheet_uri(). 'js/script.js', array('jquery'), '3.2.1', false);
}
    add_action('wp_enqueue_scripts','cool_scripts');
在我的script.js文件中,以下是我的代码:

function cool_scripts(){

    wp_enqueue_script('cool-stuff', get_stylesheet_uri(). 'js/script.js', array('jquery'), '3.2.1', false);
}
    add_action('wp_enqueue_scripts','cool_scripts');
//带有类div
jQuery(文档).ready(函数(){
$(“.videowidth”).hover(函数(){
$(此).children(“视频”)[0].play();
},
函数(){
$(此).children(“视频”)[0]。暂停();
});
});
//没有id和class div
/*$(文档).ready(函数(){
$(“视频”).hover(函数(){
$(此[0].play();
},
函数(){
$(此)[0]。暂停();
});

});*/
您需要使用
get\u stylesheet\u directory\u uri()
而不是
get\u stylesheet\u uri()

有关是选择
get\u template\u directory\u uri
还是
get\u stylesheet\u directory\u uri

我找到它的更多信息,请参阅

(function($) {
    $(function() {
        $('video').hover(function() {
            this.play();
        }, function() {
            this.pause()
        });
    });
})(jQuery);

谢谢我没有看到他使用get_stylesheet_directory_uri()而不是get_stylesheet_uri()。我会去看看你提供的链接。但现在我的控制台上出现了另一个错误,上面写着“script.js?ver=3.2.1:3 uncaughttypeerror:$不是函数”。就在那行代码上:“$(.videowidth”).hover(function(){”.我在网上读到,有时你必须用jQuery替换$才能使其工作。这是真的吗?因为当我把脚本放在正文中时,它在HTML文件上工作。我想要实现的是当我将鼠标移到图标上时播放视频。我像在HTML文件上所说的那样对它进行了测试,但当我在wordpress上测试时,它不起作用。