且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以获取图像并通过ajax加载到div中吗

更新时间:2023-01-21 19:57:51

您还必须删除当前附加的图像.这是一个点击事件和图像,而不是附加标记.

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;
});