从JQuery创建iframe - 属性不起作用,为什么不呢?
问题描述:
你好我创建一个iframe在我的JavaScript。然而,风格和加载的事件似乎不起作用。我究竟做错了什么?从JQuery创建iframe - 属性不起作用,为什么不呢?
var iframe = $("<iframe src='/Player/ShowPage/"+data.PageId+"'/>", {
style: "position:absolute; left:-100%",
load: function() {
var that = this;
$(this).animate({
left: 0
}, 500);
$('iframe').not(this).animate({
left: '-100%'
}, 500, function() {
$('iframe').not(that).remove();
});
}
});
$('body').append(iframe);
我一定错过了一些东西,我只是不知道它是什么。 iframe只是坐在那里 - 嘲笑我 - 在屏幕上...
答
你只需要将'src'移动到对象字面值,一切正常。
var iframe = $("<iframe>", {
src: '/Player/ShowPage/' + data.PageId,
style: "position:absolute; left:-100%",
load: function() {
var that = this;
$(this).animate({
left: 0
}, 500);
$('iframe').not(this).animate({
left: '-100%'
}, 500, function() {
$('iframe').not(that).remove();
});
}
});
$('body').append(iframe);
请检查这个JSFIDDLE进行工作演示。
+0
Yesss ....对我来说似乎很奇怪,但它只是一个那些你不想太多的东西,谢谢。 –
该属性被命名为'onload',而不是'load'。 – Guffa
或者使用iframe.on('load',func ....' – charlietfl
whats buggin me,is that“style”is not either either ... –