我正在开发一个使用 cookie 的程序。这是一个购物车应用程序。我想问的是,有什么方法可以让用户输入的确切值存储在 cookie 中?
我的页面设置方式是一个表格中有两个项目已经设置了价格,用户只输入数量。用户输入数量,点击添加到购物车,然后点击链接查看购物车。该链接将用户带到另一个页面,该页面的数量、价格和总价显示在表格中。
我的查看购物车页面现在显示用户输入的数量。但现在我的下一个问题是获取要显示的每个项目的总数。我尝试使用我的 retr() 函数中的最后一行代码,但没有任何成功。有任何想法吗?这是我的查看购物车链接页面
<html>
<head>
<title> Cart </title>
<h1> My cart </h1>
<script type = "text/javascript">
function retr()
{
var cke = document.cookie;
if (cke.length>0) {
start = cke.indexOf("Circle=");
if (start!= -1) {
start = start + 7
end = cke.indexOf("$", start);
if (end == -1) end = cke.length;
qu1 = cke.substring(start, end);
document.getElementById("q1").value = qu1;
}
}
if (cke.length>0) {
start = cke.indexOf("$");
if (start!= -1) {
start = start + 1
end = cke.indexOf("e", start);
if (end == -1) end = cke.length;
pr1 = cke.substring(start, end);
document.getElementById("p1").value = pr1;
}
}
if (cke.length>0) {
start = cke.indexOf("Stickman=");
if (start!= -1) {
start = start + 9
end = cke.indexOf("$", start);
if (end == -1) end = cke.length;
qu2 = cke.substring(start, end);
document.getElementById("q2").value = qu2;
}
}
if (cke.length>0) {
start = cke.indexOf("$");
if (start!= -1) {
start = start + 55
end = cke.indexOf("e", start);
if (end == -1) end = cke.length;
pr2 = cke.substring(start, end);
document.getElementById("p2").value = pr2;
}
}
document.getElementById("t1").value = qu1 * pr1;
document.getElementById("tot").value = document.getElementById("t1") + document.getElementById("t2");
}
</script>
</head>
<body onload = "retr()">
<table border = "1">
<td>Circle </td>
<td><input type = "text" size = "8" id = "q1" readonly = "readonly" /></td>
<td> <input type = "text" size = "8" id = "p1" readonly = "readonly" /> </td>
<td> <input type = "text" size = "8" id = "t1"> </td>
<tr> </tr>
<td> Stickman </td>
<td> <input type = "text" size = "8" id = "q2" readonly = "readonly" /></td>
<td> <input type = "text" size = "8" id = "p2" readonly = "readonly" /> </td>
<td> <input type = "text" size = "8" id = "t2"> </td>
<tr> </tr>
<td colspan = "3"> TOTAL: </td>
<td> <input type = "text" size = "8" id = "tot"> </td>
</table>
<br /> <br />
<input type ="text" id = "ret" readonly = "readonly" />
<br / > <br />
<input type = "button" value = "Checkout">
<br /> <br />
<a href = "store.html" > Continue Shopping </a>
</body>
</html>