&引用;Can';t从释放的脚本执行代码";在IE8中使用Javascript w/Prototype
这是我的第一个问题,接下来 我在IE8中遇到了一个问题,我有一个弹出表单(&引用;Can';t从释放的脚本执行代码";在IE8中使用Javascript w/Prototype,javascript,internet-explorer-8,prototypejs,Javascript,Internet Explorer 8,Prototypejs,这是我的第一个问题,接下来 我在IE8中遇到了一个问题,我有一个弹出表单(window.showDialog())用于编辑会计系统中的收据信息 在我不得不通过添加一个动态构建的输入字段表来添加更多内容之前,这一切都很正常。我正在以数组的形式获取信息,但是这就是我的错误似乎发生的地方var pinput=[]似乎是导致问题的原因 弹出窗体中的js函数: function saveForm() { if($('user_id')){ var user_id = $F('user_id');
window.showDialog()
)用于编辑会计系统中的收据信息
在我不得不通过添加一个动态构建的输入字段表来添加更多内容之前,这一切都很正常。我正在以数组的形式获取信息,但是这就是我的错误似乎发生的地方<代码>var pinput=[]代码>似乎是导致问题的原因
弹出窗体中的js函数:
function saveForm() {
if($('user_id')){
var user_id = $F('user_id');
} else {
var user_id = 0;
}
var payments = $$('.payment');
var pinputs = [];
for(var i=0; i<payments.length; i++){
pinputs.push($F(payments[i]));
}
window.returnValue = {received_of: $F('received_of'), user_id: user_id,
note: $F('note'), work_date: $F('work_date'), payment: pinputs};
window.close();
}
我在这里已经发现了一个类似的情况,但是这涉及到从子窗体调用函数,我在这里没有这样做。也许我不明白答案?我不是JS方面的专家,所以任何输入都会有帮助
--编辑--
忘了在这里添加
var payments=$$('.payment')
是我的模板文件中输入字段的数组。您可能试图在关闭弹出窗口后访问弹出窗口返回的数组中的方法。返回的数组是在弹出窗口上构建的,它依赖于仍然存在的可用弹出窗口
因此,您有几个选择:
- 不要从弹出脚本中关闭弹出窗口。让您的父处理程序对数组执行所需的操作(例如,使用
将其克隆到自己的数组中),然后让它关闭弹出窗口[].concat(popupArray)
- 将数组转换为字符串以跨越弹出窗口/父边界<如果您不关心IE6/7,code>JSON.stringify()/JSON.parse()将很好地完成这项工作。这样,您仍然可以从弹出脚本中关闭弹出窗口(很明显,字符串对象在IE中没有特殊问题。)
- 我也有同样的问题,所以我编写了这个方便的函数来解决这个问题
// The array problem is when modalDialogue return values are arrays. The array functions
// such as slice, etc... are deallocated when the modal dialogue closes. This is an IE bug.
// The easiest way to fix this is to clone yourself a new array out of the remnants of the old.
//
// @param[in] ary
// The array, which has been passed back from a modal dialogue (and is broken) to clone
// @returns
// A new, unbroken array.
function cloneArray(ary) {
var i;
var newAry = [];
for(i=0; i<ary.length; i++){
if(Object.prototype.toString.call(ary[i]) == '[object Array]') {
newAry.push(cloneArray(ary[i]));
} else{
newAry.push(ary[i]);
}
}
return newAry;
}
确保将页面上所有的
标记移到所有
标记之上。是的,这是我在研究这个问题时发现的第一件事。这不是我问题的原因。不过,谢谢你的回复:正如我之前所说的,我已经查过那篇文章了。我觉得情况不一样。
// The array problem is when modalDialogue return values are arrays. The array functions
// such as slice, etc... are deallocated when the modal dialogue closes. This is an IE bug.
// The easiest way to fix this is to clone yourself a new array out of the remnants of the old.
//
// @param[in] ary
// The array, which has been passed back from a modal dialogue (and is broken) to clone
// @returns
// A new, unbroken array.
function cloneArray(ary) {
var i;
var newAry = [];
for(i=0; i<ary.length; i++){
if(Object.prototype.toString.call(ary[i]) == '[object Array]') {
newAry.push(cloneArray(ary[i]));
} else{
newAry.push(ary[i]);
}
}
return newAry;
}
var selectedAry = window.showModalDialog("Window.jsp", inputAry, "dialogWidth:900px; dialogHeight:700px; center:yes; resizable: yes;");
var newAry = cloneArray(selectedAry);