document.write在Chrome中无效

时间:2015-10-12 11:02:20

标签: javascript html document.write

我正在使用html和js创建购物车。我使用document.write返回购物车的值。

Firefox和IE正确显示,但在Chrome中,字段为空白。知道为什么会这样吗?

在第1页,用户将商品添加到购物车。这很好用。但是当信息发送到我的第二页,用户可以在其中添加结帐信息时,Chrome中的购物车信息会丢失(但不会丢失在Firefox或IE中)。

以下是第2页上购物车的代码 - 问题可能出在这里?:

<table border="1" cellpadding="4" cellspacing="2">
<tr>
    <td><p>Quantity</p></td>
    <td><p>Item</p></td>
    <td><p>Unit Cost</p></td>
    <td><p>Total Cost</p></td>
</tr>


<script>
var numitems = opener.numitems;
var totcost = 0;

for (i=1; i<=numitems; i++)
{
    if(opener.items[i] != null)
    {
        if(opener.items[i].M_quantity > 0)
    {

        document.write("<tr><td><p style=text-align:center>" + opener.items[i].M_quantity);
        document.write("</p></td><td><p style=text-align:center>" + opener.items[i].M_desc);
        document.write("</p></td><td><p style=text-align:center>" + opener.items[i].M_price);
        cost = opener.items[i].M_price * opener.items[i].M_quantity;
        totcost += cost;
        totcost2 = totcost;
        document.write("</p></td><td><p style=text-align:center>" + cost);
        document.write("</p></td></tr>\n");
        // hidden fields for returning in callback
        document.write("<input type=hidden name='M_qty" + i + "'");
        document.write(" value='" + opener.items[i].M_quantity + "'>\n");
        document.write("<input type=hidden name='M_desc" + i + "'");
        document.write(" value='" + opener.items[i].M_desc + "'>\n");
        document.write("<input type=hidden name='M_price" + i + "'");
        document.write(" value='" + opener.items[i].M_price + "'>\n");

        }
    }
}

document.write("<tr><td colspan=3><b><p>Total Cost:</p></b>");
totcost = opener.roundOff(totcost,2);
document.write("</td><td><p style=text-align:center><b>&pound;" + totcost + "</b></td></tr>");
</script>

</table>

0 个答案:

没有答案
相关问题