我有一个问题,我制作了一个贯穿所有图像的脚本,并获取图像的href并将其放到图像下的每个购买按钮。每张图片都有一个购买按钮。
但是当存在没有链接的图像时,脚本会停止并且不会继续结束。
我怎么能让它一直持续到最后?
发现某个地方return non-false;
就像继续,但没有效果。
不允许把标记抱歉。
$('.productImg a').each(function(){
if($(this).attr('href').indexOf("sometext")> 0 && $(this).attr('href').indexOf("sometext") != 'undefined'){
$(this).parents(".item").find(".BuyLink a").attr('href',$(this).attr('href'));
}
else if ($(this).attr('href').indexOf("sometext") == 'undefined') {
return non-false;
}
});
答案 0 :(得分:1)
$('.productImg a').each(function(){
if (!$(this).attr('href')) // <--- This checks if the image has a link
return;
if($(this).attr('href').indexOf("sometext")> 0 && $(this).attr('href').indexOf("sometext") != 'undefined'){
$(this).parents(".item").find(".BuyLink a").attr('href',$(this).attr('href'));
}
});