你好,我在我的 javascript 中创建了一个 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 只是坐在那里 - mock 我 - 在屏幕上......
最佳答案
您只需将“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一个工作演示。
关于javascript - 从 JQuery 创建 iframe - 属性不起作用,为什么不呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31550058/