【发布时间】:2021-03-15 04:54:50
【问题描述】:
我正在为一个课程项目复制一个杂货店网页,并且想知道即使在网页刷新后如何保持数量框中的值。
<button type="button" id="subtract" onclick="decrease()">-</button>
<input class="quantity-box" type="text" id="text" value="0">
<button type="button" id="add" onclick="increase()">+</button>
<script>
function decrease(){
var textBox = document.getElementById("text");
if (textBox.value>0){
textBox.value--;
}
}
function increase(){
var a = 1;
var textBox = document.getElementById("text");
textBox.value++;
}
</script>
注意:我可以使用 AJAX,但我对此并不熟悉,所以如果它包含在解决方案中,简要说明就足够了。 HTML/JAVASCRIPT/CSS/AJAX
【问题讨论】:
-
本地存储可能是这里的一种可能性developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
标签: javascript html css ajax