开发者

Use Ajax or Attributes for Images

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜