Javascript 用iframe替换图像

Javascript 用iframe替换图像,javascript,jquery,html,iframe,widget,Javascript,Jquery,Html,Iframe,Widget,我正在尝试使用JQuery将img标记替换为带有iframe的特定src标记。 这是外部小部件脚本实现的一部分。这是我用来用带有iframe的特定src替换图像的代码: function main() { jQuery(document).ready(function($) { var img = $("img[src='http://fc01.deviantart.net/fs17/f/2007/129/7/4/Stock_032__by_enchanted_stock.jpg']")[0

我正在尝试使用JQuery将img标记替换为带有iframe的特定src标记。 这是外部小部件脚本实现的一部分。这是我用来用带有iframe的特定src替换图像的代码:

function main() {
jQuery(document).ready(function($) {
  var img = $("img[src='http://fc01.deviantart.net/fs17/f/2007/129/7/4/Stock_032__by_enchanted_stock.jpg']")[0];
  var width;
  var height;
  var id = 47;
  $("<img/>") 
      .attr("src", $(img).attr("src"))
      .load(function() {
          width = this.width;   
          height = this.height; 
          var widgetReplace = "<iframe src=&quothttp://localhost:5000/app/#/widget" + id + "?height=" + height + "px&width=" + width + "px frameborder='0' height=&quot" + height + "&quot width=&quot" + width + "&quot style='overflow:'hidden';&quot></iframe>"; 
          this.replaceWith(widgetReplace);
      });        
   });
  }
})();

我在this.replaceWithwidgetReplace行中得到一个未定义的错误不是一个函数。

编辑:嗯,在我发布后看到错误并不是我想象的那样,我想我错了

由于iframe的格式问题,我可能完全错了,但是看了一两分钟后,您似乎缺少了一个“。 这是有问题的一行,为了便于阅读,我删掉了很多

var widgetReplace = "<iframe src=&quothttp://localhost:5000/app/#/widget" + id + "?height="
在身份证之后还是?我相信这应该是完成src的最终报价。例如

"<iframe src=&quothttp://localhost:5000/app/#/widget" + id + "?&quotheight="

当然,根据fromatting的不同,“可能在不同的位置,我无法知道。”replaceWith方法是一个jQuery函数,因此您应该使用:

$(this).replaceWith(widgetReplace);
错误-什么错误?