通过清除src属性,使用jquery动态删除图像

Haz*_*zel 2 jquery dynamic-attributes loading-image

我知道可以使用动态加载图像

$("#id").attr("src","path of the image"),
Run Code Online (Sandbox Code Playgroud)

但要在特定事件上载入特定图像,

$("id").attr("src","")
Run Code Online (Sandbox Code Playgroud)

不起作用.

使用jquery卸载映像运行时的​​正确方法是什么?

我无法更改图像的显示或可见性属性,我需要加载它卸载它.

Sum*_*ain 7

有很多方法可以做到这一点.你可以使用适合你的那个

  1. $('#id').removeAttr('src');? // Remove the src
  2. $('#id').remove(); //This will remove the element from DOM so be careful
  3. $('#id').attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=='); // This will change the src to a 1x1 pixel

  4. $('#id').removeAttr('src').replaceWith($image.clone()); //That worked for few people