简体   繁体   English

src是图像交换上的未定义变量

[英]src is undefined variable on image swap

Having problems with a (probably) simple task of passing a variable as a src of an image. 将变量作为图像的src传递给(可能)简单的任务时遇到问题。

The variables are defined at random from an array, and then if URL criteria is met then that random variable is assigned as the src of the image. 变量是从数组中随机定义的,然后如果满足URL条件,则将该随机变量分配为图像的src。

jQuery: jQuery的:

var imgpathnamesfor7offers = ["offers1.jpg", "offers2.jpg", "offers3.jpg", "offers4.jpg"];
var randompathname = imgpathnamesfor7offers[Math.floor(Math.random() * imgpathnamesfor7offers.length)];
var produrl = jQuery(location).attr('href');
var icatRef = produrl.split("/")[4];
if (icatRef == "shark-steam-cleaning") {
    jQuery("#prodpagesliderbar-img").attr("src", jQuery("#prodpagesliderbar-img").attr("src").replace(randompathname));
}

Link: http://jmldirect.uat.venda.com/uk/shark-steam-cleaning/shark-lift-away-steam-pocket-5-in-1/invt/s06lt30100000001 链接: http//jmldirect.uat.venda.com/uk/shark-steam-cleaning/shark-lift-away-steam-pocket-5-in-1/invt/s06lt30100000001

Can anyone see what I'm doing wrong? 谁能看到我在做什么错? Console appends 'undefined' to the end of the src. 控制台将“未定义”附加到src的末尾。

instead of this: 代替这个:

jQuery("#prodpagesliderbar-img").attr("src").replace(randompathname)

this should be: 这应该是:

jQuery("#prodpagesliderbar-img").attr("src", randompathname)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM