嗨,我正在使用 jQuery 创建一个输入数字增量,但没有成功,请您检查我的代码并给我适当的指导
HTML
<div class="sp-quantity">
<div class="sp-minus fff"> <a class="ddd" href="#">-</a></div>
<div class="sp-input">
<input type="text" class="quntity-input" value="1">
</div>
<div class="sp-plus fff"> <a class="ddd" href="#">+</a></div>
</div>
JS
$(".ddd").on("click", function () {
var $button = $(this);
var oldValue = $button.parent().find("input .quntity-input").val();
if ($button.text() == "+") {
var newVal = parseFloat(oldValue) + 1;
} else {
// Don't allow decrementing below zero
if (oldValue > 0) {
var newVal = parseFloat(oldValue) - 1;
} else {
newVal = 0;
}
}
$button.parent().find("input .quntity-input").val(newVal);
});