无法修复显示Javascript中的错误

时间:2019-10-13 20:47:20

标签: javascript html

以前,我在html页面之间传输数据时遇到问题,但是很幸运,我得到了帮助。但是,我在显示某些购物车页面上显示的价格并将其显示在结帐页面时遇到了一些麻烦。他们通过本地浏览器存储来执行此操作的方式是,我被告知可以使用多个实例来完成此操作,但是我一定会丢失某些内容。

here is a pseudo code: 
unique_report_name = ("rep" + str(randint(100, 200)))
create report...
search created report...
result = driver.find_elements_by_xpath("//*[contains(text(),'Report Name :"unique_report_name"')]")  
  if result is displayed: 
    do something...
//table.html
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8"/>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>

<body>

<h2>Html Table</h2>

<table id="EstoreTable" style="width:100%">
  <tr>
    <th>Item Name</th>
    <th>Quantity</th> 
    <th>Price</th>
  </tr>
  <tr>
    <td>iPhone X</td>
    <td>10</td>
    <td>299.99</td>
  </tr>
  <tr>
    <td>Apple Watch 3</td>
    <td>12</td>
    <td>250.00</td>
  </tr>
  <tr>
    <td>MacBook Pro 13" </td>
    <td>7</td>
    <td>1199.99</td>
  </tr>
</table>
    <a href="assign1_agm75_checkout.html" target="_blank" id="checkout">Checkout</a>
    <script src="CheckoutAmounts.js"></script>
    </body>  

</html>
//js file
function getCheckoutAmounts()
{ 
    var table = document.getElementById('EstoreTable'); //data from TestTable.html
    var sum = 0,
        taxTotal = 0,
        tax = .0825,
        shipping = 5.99,
        due = 0;

    for (var i = 1; i < table.rows.length; i++)
        {
           sum = sum + parseFloat(table.rows[i].cells[2].innerHTML); //stores total price into sum
        }

    taxTotal = tax * sum; //stores calculated tax

    due = sum + taxTotal + shipping;

    // SET VIA query string
    this.href += "?sum=" + sum;
    this.href += "?taxTotal=" + taxTotal;
    this.href += "?shipping=" + shipping;
    this.href += "?due=" + due;

    // SET SUM VIA localStorage
    window.localStorage.setItem("sum", sum);
    window.localStorage.setItem("taxTotal", taxTotal);
    window.localStorage.setItem("shipping", shipping);
    window.localStorage.getItem("due", due);

}

document.querySelector("#checkout").addEventListener("click", getCheckoutAmounts);

但是,当我运行JS时,这是我在//Checkout.html <html> <h1>Checkout</h1> Total Shopping Amount: $<span id="Shopamount"></span><br> Total Tax: $<span id="TaxTotal"></span><br> Total Shipping Charges: $<span id= "charges"></span><br> Total Amount Due: $<span id="total"></span><br> <script> // GET data VIA localStorage document.querySelector("#Shopamount").textContent = window.localStorage.getItem("sum"); document.querySelector("#TaxTotal").textContent = window.localStorage.getItem("taxTotal"); document.querySelector("#charges").textContent = window.localStorage.getItem("shipping"); document.querySelector("#total").textContent = window.localStorage.getItem("due"); // GET SUM VIA query string let queryString = document.location.search; let sum = queryString.split("=")[1]; let taxTotal = queryString.split("=")[1]; let shipping = queryString.split("=")[1]; let due = queryString.split("=")[1]; document.querySelector("#Shopamount").textContent = sum; document.querySelector("TaxTotal").textContent = taxTotal; document.querySelector("charges").textContent = shipping; document.querySelector("total").textContent = due; </script> Total Shopping Amount: $ $1749.98?taxTotal Total Tax: $144.37335000000002 Total Shipping Charges: $5.99 Total Amount Due: $ 中得到的结果。checkout.html中还有其他部分,因此没有封闭标记。

0 个答案:

没有答案