开发者

Use Ajax or Attributes for Images

开发者 https://www.devze.com 2023-02-14 03:54 出处:网络
What is better for dynamically loading images- using an ajax function or changing the image\'s src attribute to the 开发者_开发技巧desired link?

What is better for dynamically loading images- using an ajax function or changing the image's src attribute to the 开发者_开发技巧desired link? Please supply a snippet of code with your answer. Thanks


Depends on your definition of "better," but since JavaScript really doesn't deal well with binary streams, I'd recommend the "changing the image's src attribute" option.

var mySource = '/path/to/image.jpg';

var img = new Image();
img.src = mySource;

// or

$('#someImageId').attr('src', mySource);
0

精彩评论

暂无评论...
验证码 换一张
取 消