我真的不知道这里有什么问题。据我所知,代码很简单,应该可以正常工作。
var Prices="";
for (var PriceCount = 1; PriceCount <= 120; PriceCount++) {
var CurrentPrice = "Price" + PriceCount;
if (prevDoc.getElementById(CurrentPrice).value != null) {
if (Prices == "") {
Prices = prevDoc.getElementById(CurrentPrice).value;
} else {
Prices += "," + prevDoc.getElementById(CurrentPrice).value;
}
} else {
break;
}
}
表单上最多可以有 120 个隐藏输入。当我们检查一个不存在的输入时,循环应该会中断。我的测试页面有两个被拉出的输入元素。在第三个(null)上,我在 firebug 中收到此错误:
prevDoc.getElementById(CurrentPrice) is null
if (prevDoc.getElementById(CurrentPrice).value != null) {
是的,它是空的……这就是 ಠ_ಠ 的检查</p>
有谁知道我做错了什么?这似乎应该是非常直截了当的。
编辑:为清楚起见,prevDoc=window.opener.document