这是我在这里的第一个问题,所以这里就是....
我在IE8中遇到了一个问题,我有一个弹出窗体(window.showDialog()
),用于编辑会计系统中的收据信息。
这个工作正常,直到我不得不通过添加动态构建的输入字段表来添加更多内容。我在数组中获取信息,但这就是我的错误似乎正在发生的地方。 var pinputs = [];
似乎是造成这个问题的原因。
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();
}
父ps文件中的js函数:
function modifyReceiptInformation(id) {
return window.showModalDialog('mod.php?mod=receipts&mode=receipt_edit_popup&wrapper=no&receipt_id=' + id, 'Modify Receipt',"dialogWidth:600px;dialogHeight:500px");
}
我在这里已经发现了类似的情况,但这涉及从子表单调用函数,我在这里没有这样做。也许我不明白解决方案?我不是JS的专家,所以任何输入都会有所帮助。
- 编辑 -
忘了也在这里添加var payments = $$('.payment');
是我的模板文件中的输入字段数组。
答案 0 :(得分:4)
您可能在弹出窗口关闭后尝试访问弹出窗口返回的数组上的方法。返回的数组是在弹出窗口上构建的,并且依赖于仍然存在的弹出窗口可用。
所以你有几个选择:
不要在弹出脚本中关闭弹出窗口。让你的父处理程序用数组做它需要的东西(例如用[].concat(popupArray)
克隆它自己的数组),然后让它关闭弹出窗口。
将数组转换为字符串以跨越弹出/父边界。如果您不关心IE6 / 7,JSON.stringify()/JSON.parse()
可以很好地完成工作。这样,您仍然可以从弹出脚本中关闭弹出窗口(显然,字符串对象不会在IE中遇到特定问题。)
答案 1 :(得分:4)
我遇到了同样的问题,所以我写了这个方便的功能来解决这个问题。
// 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);