Can I get the image and load via ajax into div

前端 未结 4 1901
星月不相逢
星月不相逢 2020-12-06 08:07

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?<

4条回答
  •  一向
    一向 (楼主)
    2020-12-06 08:47

    If you want to change image dynamically use dom What you need to do is change the img src attribute

    say img_div is your parent element then

    var im = document.createElement('img');
    im.src = 'image_path1';
    img_div.appendChild(im);
    

    on some event if you want to change this image

    im.src = 'image_path2'
    

提交回复
热议问题