简体   繁体   中英

rails turbolinks onerror javascript

I want to hide an image when the link of the image is broken (404 not found). When i trigger an onerror:hideImage(this) on my image it works once and then because of Turbolinks, it hides all the images after a refresh. Is there a solution?

function hideImage(source){
    source.hide();
}

Thanks

Ok, found the solution:

add onerror:"this.style.display='none'" to your image_tag and it's done!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM