我能得到的图像和负载通过AJAX到DIV [英] Can I get the image and load via ajax into div
本文介绍了我能得到的图像和负载通过AJAX到DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code和我需要做的是通过AJAX ...任何帮助AP preciated加载从HREF的图像转换成一个div。我相信,负载()无法加载像这样的图片?
I have the code below and what I need to do is load the image from the href into a div via ajax... Any help appreciated. I believe that load() can't load images like this?
<ul id="list">
<li class="list-item-1"><a href="images/image1.jpg">Image 1</a></li>
<li class="list-item-2"><a href="images/image2.jpg">Image 2</a></li>
<li class="list-item-3"><a href="images/image3.jpg">Image 3</a></li>
<li class="list-item-4"><a href="images/image4.jpg">Image 4</a></li>
</ul>
<div id="image-holder"></div>
非常感谢, ç
Many thanks, C
推荐答案
您也必须删除当前附加的图像。这是一个点击事件,而不是附加标记和图像。
You have to also remove the currently appended image. Here it is with a click event and Image instead of appending markup.
$('#list li a').click(function () {
var url = $(this).attr('href'),
image = new Image();
image.src = url;
image.onload = function () {
$('#image-holder').empty().append(image);
};
image.onerror = function () {
$('#image-holder').empty().html('That image is not available.');
}
$('#image-holder').empty().html('Loading...');
return false;
});
这篇关于我能得到的图像和负载通过AJAX到DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文