Javascript 在jQuery对象中将绝对路径添加到img

Javascript 在jQuery对象中将绝对路径添加到img,javascript,jquery,html,Javascript,Jquery,Html,我想从外部站点上的特定div中提取一些数据,将URL预附加到img src链接(它们是相对的),使其成为绝对的,然后将html放入div中。忽略跨站点问题 jQuery(document).ready(function() { var $thePage = jQuery('<div>'); jQuery($thePage).load("https://example.com div.myitem"); jQuery($thePage).find('img').attr('

我想从外部站点上的特定div中提取一些数据,将URL预附加到img src链接(它们是相对的),使其成为绝对的,然后将html放入div中。忽略跨站点问题

jQuery(document).ready(function() {
  var $thePage = jQuery('<div>');
  jQuery($thePage).load("https://example.com div.myitem");
  jQuery($thePage).find('img').attr('src', function (i, src) {
    var newsrc = "https://example.com" + src;
    return newsrc;
  });
  jQuery("#testdiv").html($thePage);
});

html显示在div中,但img链接不会更新。任何想法都将不胜感激

jQuery.load是异步的,因此您应该在回调中处理返回的数据

  jQuery($thePage).load("https://example.com div.myitem", function () {
    // replace stuff here
    // show output on page here
  });

当前结果和预期结果是什么?