How to get the src of a clicked image with prototype

天大地大妈咪最大 提交于 2019-12-13 05:22:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!