问题
I am struggling to get the image src of a image when its clicked. I just need the jQuery(this).attr("src") but in prototype, this.readAttribute doesn't work. I get: “this.readAttribute is not a function”
$$('.more-views > ul > li > img').invoke('observe', 'click', this.updateImage.bind(this));
updateImage: function (){
//var src = jQuery(this).attr("src").replace("thumbnail/66x66", "image");//changes src from thumbnail to large image
Needs the above but in prototype.
//jQuery('#image').attr("src", src);//updates large image
this.imageEl.writeAttribute("src","http://www.timelapseme.com/images/logonew.png");
val_scale = !this.showFull ? this.slider.value : 1;
this.scale(val_scale);
},
回答1:
Try this:
updateImage: function (){
var src = $(this).readAttribute('src');
...
}
回答2:
Thanks wajiw I fixed it by var that = this, so I could use it later and getting rid of .bind(this)
回答3:
You're binding an event, so the click-handler should be:
...
updateImage: function(event)
{
var img = Event.findElement(event, 'IMG');
var src = img.src;
}
...
来源:https://stackoverflow.com/questions/4298329/how-to-get-the-src-of-a-clicked-image-with-prototype