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);
精彩评论