$('<img />')
.attr('src', val)
.attr('width', "400")
.load(function(){
$('.showdata').append( $(this) );
}
);
这对图像非常有效,如何将 1:1 转换为 iframe?这里快速jsfiddle:http: //jsfiddle.net/ET8Gw/
$('<img />')
.attr('src', val)
.attr('width', "400")
.load(function(){
$('.showdata').append( $(this) );
}
);
这对图像非常有效,如何将 1:1 转换为 iframe?这里快速jsfiddle:http: //jsfiddle.net/ET8Gw/
与 Image 对象不同,IFrame 在成为 DOM 的一部分之前不会加载。
要解决这个问题,您可以隐藏元素,将其添加到 DOM,并在加载事件触发时显示它:
var val = "http://dumb.com/";
$('<iframe />')
.hide()
.attr('src', val)
.attr('width', "500")
.load(function(){
$(this).show();
})
.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'));
尝试这样的事情:
$("<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>');
jsfiddle:http: //jsfiddle.net/ET8Gw/22/