设置图片的src属性在Chrome中不起作用 [英] Setting image src attribute not working in Chrome

查看:432
本文介绍了设置图片的src属性在Chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这个没有成功。



我想获取一张图片的 src 并将其设置为另一个图片的 src 当按下 #btn 时:

  jQuery (#btn)。live(click,function(){
jQuery(#another_div)
.children(img)
.attr(src, jQuery(this).prev(img)。attr(src));
jQuery(this)
.prev(img)
.attr(src, );
})

我也试过:

  jQuery(this).prev('img')。removeAttr(src); 

在Firefox,IE7-9和Safari中正常工作。



只有在Chrome中,即使源文件发生更改( src =),图片也不会被删除。


<您可以将其更改为

  jQuery(this)。

attr(src,data:image / gif; base64,R0lGODlhAQABAIAAAP /////// yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw ==);

也许?


I have tried this without success.

I want to get the src of one image and set it as another's src when #btn is pressed:

jQuery("#btn").live("click", function() {
    jQuery("#another_div")
        .children("img")
        .attr("src", jQuery(this).prev("img").attr("src"));
    jQuery(this)
        .prev("img")
        .attr("src","");
})

I have also tried:

jQuery(this).prev('img').removeAttr("src");

It works fine in Firefox, IE7-9, and Safari.

Only in Chrome, the image is not removed even when the source changes (src="").

解决方案

You could change it to

jQuery(this).attr("src", "data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==");

maybe?

这篇关于设置图片的src属性在Chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆