我试图创建增加或减少数量值的按钮。HTML/JavaScript - 数量不起作用的向上和向下按钮
HTML:
<div class="order-option">
Quantity:
<span id="quantity-field">
<button id="up" onclick="setQuantity('up');">+</button>
<input type="text" id="quantity" value="1">
<button id="down" onclick="setQuantity('down');">-</button>
</span>
</div>
的JavaScript:
function setQuantity(upordown) {
var quantity = document.getElementById('quantity');
if (quantity.value > 1) {
if (upordown == 'up'){++document.getElementById('quantity').value;}
else if (upordown == 'down'){--document.getElementById('quantity').value;}}
else if (quantity.value == 1) {
if (upordown == 'up'){++document.getElementById('quantity').value;}}
else
{document.getElementById('quantity').value=1;}
}
这是很添油加醋。该功能根据点击哪个按钮而向上或向下传递,然后根据数量元素的当前值确定要执行的操作。不幸的是,它没有做一件事,我不明白为什么。任何帮助将非常感激。
我们可以看到一个[小提琴](http://jsfiddle.net)? – Mooseman
它适用于我 – edi9999