Function Prototype-each()中的函数-仅返回最后一个值

Function Prototype-each()中的函数-仅返回最后一个值,function,prototypejs,each,Function,Prototypejs,Each,我试图从每个缩略图加载图像并添加一个Opentip(Opentip.org) 我已经成功地添加了标记并创建了工具提示。唯一的问题是,对于每个缩略图,只显示数组中的最后一个值 以下是一个产品的链接: 原始HTML是 我相信函数image()只获取最后一项 有人对此有线索吗? 对不起,我的英语不好 谢谢当您需要时,图像函数不会被调用。我不能100%确定它为什么没有出错,但不是将元素传递给addTip,而是传递对函数的引用(image)。尝试此操作以查看是否解决了此问题: var tip = $$('

我试图从每个缩略图加载图像并添加一个Opentip(Opentip.org)

我已经成功地添加了标记并创建了工具提示。唯一的问题是,对于每个缩略图,只显示数组中的最后一个值

以下是一个产品的链接:

原始HTML是

我相信函数image()只获取最后一项

有人对此有线索吗? 对不起,我的英语不好


谢谢

当您需要时,
图像
函数不会被调用。我不能100%确定它为什么没有出错,但不是将元素传递给addTip,而是传递对函数的引用(
image
)。尝试此操作以查看是否解决了此问题:

var tip = $$('.ca-thumbnails div img');
tip.each(function(s, index) {

    var src = s.readAttribute('src');
    var image = new Element('img', {src: src});

    s.wrap('a', { 'class': 'tip', 'onclick':'return false;', 'href': src});
    s.up(0).addTip(image, { ajax: false, showEffect: 'appear',  showon:'mouseover', className:'glass', containInViewport: true, target: true, stem: true,   tipJoint: [ 'center', 'bottom' ], targetJoint: [ 'center', 'top' ] });
});
不要忘记使用
var
关键字!我看到您有一个全局
image
变量,它可能(也可能不)与为什么这些特定的代码行没有出错有关,并为您提供错误的线索

var tip = $$('.ca-thumbnails div img');
tip.each(function(s, index) {

   src = s.readAttribute('src');
   function image() {

    return Builder.node('img', { 'src': src });
   }

    s.wrap('a', { 'class': 'tip', 'onclick':'return false;', 'href': src});
    s.up(0).addTip(image, { ajax: false, showEffect: 'appear', showon:'mouseover', className:'glass', containInViewport: true, target: true, stem: true, tipJoint: [ 'center', 'bottom' ], targetJoint: [ 'center', 'top' ] });
var tip = $$('.ca-thumbnails div img');
tip.each(function(s, index) {

    var src = s.readAttribute('src');
    var image = new Element('img', {src: src});

    s.wrap('a', { 'class': 'tip', 'onclick':'return false;', 'href': src});
    s.up(0).addTip(image, { ajax: false, showEffect: 'appear',  showon:'mouseover', className:'glass', containInViewport: true, target: true, stem: true,   tipJoint: [ 'center', 'bottom' ], targetJoint: [ 'center', 'top' ] });
});