为什么找不到mi javascript上的图像?

时间:2017-02-28 作者:Ramses

我的页面在wordpress中,我正在尝试使用页脚中的下一个代码为该im包含一个javascript文件:

<script src="<?php bloginfo(\'template_url\')?>/js/main.js"></script>
文件似乎加载正确,但在javascript代码中,我称之为一些图像。

function sliderimgchange(){

        if ($(window).width() <= 600) {

        var sliderOne  =  $(\'.slideuno\').attr(\'src\', \'../images/sliderone-mobile.jpg\'),
        sliderTwo  =  $(\'.slidedos\').attr(\'src\', \'../images/slidertwo-mobile.jpg\'),
        sliderThree  =  $(\'.slidetres\').attr(\'src\', \'../images/sliderthree-mobile.jpg\');

        } else if ($(window).width() > 600) {

        var sliderOne  =  $(\'.slideuno\').attr(\'src\', \'../../images/sliderone.jpg\'),
        sliderTwo  =  $(\'.slidedos\').attr(\'src\', \'../../images/slidertwo.jpg\'),
        sliderThree  =  $(\'.slidetres\').attr(\'src\', \'../../images/sliderthree.jpg\');
        }
    }
当我转到页面时,该javascript文件中的所有图像都没有加载。我检查了控制台,错误显示找不到图像。我想知道如何调用此scritp,以便在我转到页面时识别图像。

1 个回复
SO网友:David Lee

你失踪了/wp-content/themes/YOUR_theme_NAME_FOLDER 像这样:

function sliderimgchange(){

        if ($(window).width() <= 600) {

        var sliderOne  =  $(\'.slideuno\').attr(\'src\', \'/wp-content/themes/YOUR_theme_NAME_FOLDER/images/sliderone-mobile.jpg\'),
        sliderTwo  =  $(\'.slidedos\').attr(\'src\', \'/wp-content/themes/YOUR_theme_NAME_FOLDER/images/slidertwo-mobile.jpg\'),
        sliderThree  =  $(\'.slidetres\').attr(\'src\', \'/wp-content/themes/YOUR_theme_NAME_FOLDER/images/sliderthree-mobile.jpg\');

        } else if ($(window).width() > 600) {

        var sliderOne  =  $(\'.slideuno\').attr(\'src\', \'/wp-content/themes/YOUR_theme_NAME_FOLDER/images/sliderone.jpg\'),
        sliderTwo  =  $(\'.slidedos\').attr(\'src\', \'/wp-content/themes/YOUR_theme_NAME_FOLDER/images/slidertwo.jpg\'),
        sliderThree  =  $(\'.slidetres\').attr(\'src\', \'/wp-content/themes/YOUR_theme_NAME_FOLDER/images/sliderthree.jpg\');
        }
    }

相关推荐

我可以使用<脚本>直接插入JavaScript吗?

我对建立Wordpress网站很陌生,所以如果我不能正确描述事情,请原谅我。有一个网站提供。屏幕上飞行蝙蝠的js文件。https://www.delphitools.info/2013/10/30/pimp-your-website-with-an-halloween-bat/它说我可以使用<script async src=\"https://cdn.delphitools.info/wp-content/uploads/2013/10/jsbat.js\"></script>&