这适用于Firefox但在Chrome上我得到了"未捕获的TypeError:无法读取属性&#c;' of null"关于"函数onDialogOpen()的错误{this.iframe.css({"。
function show(options) {
// create our temporary iframe
this.iframe = $('<iframe name="' + (this.id = 'emh_' + +new Date) + '">')
.load($.proxy(onIframeLoad, this));
// show our dialog
this.iframe.dialog($.extend(true, {
title: 'Entity Viewer',
modal: true,
draggable: false,
resizable: false,
width: 800,
height: 500,
buttons: {
'Save & Continue': $.proxy(submitIframeForm, this)
},
open: $.proxy(onDialogOpen, this),
close: $.proxy(onDialogClose, this)
}, options));
alert(options.path);
// since our dialog is showing now, let's update the src of the iframe
this.iframe.attr('src', options.path + '?modal=true&unique=' + this.id);
}
function onDialogOpen() {
this.iframe
.css({
width: '100%',
padding: 0,
border: 0,
margin: 0
});
}
答案 0 :(得分:0)
不确定这是否有效,但我有两种方法:
在show方法中移动onDialogOpen:
function show(options) {
//your code
//...
//...
//this.iframe.attr('src', options.path + '?modal=true&unique=' + this.id);
//no need to pass this parameter since method has same this as parent one
function onDialogOpen() {
this.iframe
.css({
width: '100%',
padding: 0,
border: 0,
margin: 0
});
}
}
或
2。 - 在IFrame加载后立即创建此引用:
var _this = this;
open:$ .proxy(function(){onDialogOpen(_this)},this)
更新onDialogOpen:
function onDialogOpen(_this) {
if (typeof _this != 'undefined')
{
_this.iframe
.css({
width: '100%',
padding: 0,
border: 0,
margin: 0
});
}
else
{
this.iframe
.css({
width: '100%',
padding: 0,
border: 0,
margin: 0
});
}
}