Javascript 将预加载img转换为iframe $('

Javascript 将预加载img转换为iframe $(',javascript,jquery,iframe,preloading,Javascript,Jquery,Iframe,Preloading,这对图像非常有效,如何将1:1转换为iFrame? 这里是快速JSFIDLE: 与图像对象不同,iFrame在成为DOM的一部分之前不会加载 要解决此问题,可以隐藏元素,将其添加到DOM中,并在load事件激发时显示它: $('<img />') .attr('src', val) .attr('width', "400") .load(function(){ $('.showdata').append( $(this) ); } ); var-

这对图像非常有效,如何将1:1转换为iFrame? 这里是快速JSFIDLE:

与图像对象不同,iFrame在成为DOM的一部分之前不会加载

要解决此问题,可以隐藏元素,将其添加到DOM中,并在load事件激发时显示它:

$('<img />')
   .attr('src', val)
   .attr('width', "400")
   .load(function(){
      $('.showdata').append( $(this) );
   }
);
var-val=”http://dumb.com/";
$('')
.hide()
.attr('src',val)
.attr('宽度',“500”)
.load(函数(){
$(this.show();
})
.附于(“.showdata”);

var-val=”http://inapcache.boston.com/universal/site_graphics/blogs/bigpicture/texas_drought_fires/bp1.jpg";
$('')
.attr('src',val)
.attr('宽度',“500”)
.appendTo($('.showdata'));

试试这样的方法:

var val = "http://inapcache.boston.com/universal/site_graphics/blogs/bigpicture/texas_drought_fires/bp1.jpg";
$('<iframe/>')
    .attr('src', val)
    .attr('width', "500")
    .appendTo($('.showdata'));
$(“”)
.css(“显示”:“无”)
.attr('src',val)
.load(
函数(){
$(this.show();
})
.附于(“.showData”);

它不能跨域工作。

我做这件事的时候让它工作了

$("<iframe></iframe>")
    .css("display":"none")
    .attr('src', val)
    .load( 
        function(){
            $(this).show();
        })
    .appendTo(".showData");
var-val=”http://inapcache.boston.com/universal/site_graphics/blogs/bigpicture/texas_drought_fires/bp1.jpg";
$('.showdata')。追加('');

“你能不能更清楚你想要达到的目标?你遇到了什么问题?”Read CeooDor,如果这个答案解决了你的问题,请考虑把它作为你的问题的解决方案,点击左边的绿色复选标记。
$("<iframe></iframe>")
    .css("display":"none")
    .attr('src', val)
    .load( 
        function(){
            $(this).show();
        })
    .appendTo(".showData");
var val = "http://inapcache.boston.com/universal/site_graphics/blogs/bigpicture/texas_drought_fires/bp1.jpg";

$('.showdata').append('<iframe src="' + val + '" width="400" height="200"><\/iframe>');