更新原型中的链接href

时间:2010-10-23 13:53:48

标签: javascript prototype lightbox

我正在运行一个原型脚本(灯箱),我想在每个图像下面添加一个额外的链接,其中的网址会随着每个图像而变化。

到目前为止,我设法将a元素添加到正确的位置,但稍后在脚本中我需要根据加载的图像更新链接的href

在加载/导航灯箱后,脚本中有一个点将图像插入灯箱:

showImage: function(){
    this.loading.hide();
    new Effect.Appear(this.lightboxImage, { 
        duration: this.resizeDuration, 
        queue: 'end', 
        afterFinish: (function(){ this.updateDetails(); }).bind(this) 
    });
    this.preloadNeighborImages();
},

完成后,它会运行updateDetails,其中包含图像的标题。在我看来,这也是更新链接的最佳位置:

updateDetails: function() {
    // if caption is not null
    if (this.imageArray[this.activeImage][1] != ""){
        this.caption.update(this.imageArray[this.activeImage][1]).show();
    }

    // if image is part of set display 'Image x of x' 
    if (this.imageArray.length > 1){
        this.numberDisplay.update( LightboxOptions.labelImage + ' ' + (this.activeImage + 1) + ' ' + LightboxOptions.labelOf + '  ' + this.imageArray.length).show();
    }

/**  slider effect cut from example code for the sake of brevity **/
 }

我根据这些功能中使用的代码尝试了很多变化,但似乎没有任何效果。如何使用href

更新链接的id=toFilePage

我认为它就像是

this.toFilePage.href.update('http://example.com');

但这似乎不起作用..

1 个答案:

答案 0 :(得分:0)

我认为问题可能在于此部分(从lightbox.js第175行开始)

(function() {
var ids = 'overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink ' + 'imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose';
$w(ids).each(function(id) {
    th[id] = $(id);
});

})推迟();

这将创建对在其上方的Builder部分中创建的对象的引用。只需将您的ID添加到该列表即可。

否则您也可以通过$("myIdHere")访问它。