我的页面在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,以便在我转到页面时识别图像。
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\');
}
}