Tenho um textbox, e dois botões mais e menos, quero decrementar até zero, consegui fazer porem não consigo diminuir de 1:
HTML
<asp:TextBox ID="txtAcrescimo" type="number" CssClass="form-control" MaxLength="18"
runat="server" onblur="javascript:defineQuantidade();"></asp:TextBox>
<div style="display: inline-block; margin-right:10px;">
<input id="aumentaAcrescimo" type="button" onclick="aumentaAcrescimo()" style="width: 35px; margin-left:10px; height: 35px" value="+" />
<td>
<input id="diminuiAcrescimo" type="button" style="width: 35px; height:35px " value="-" />
</div>
JS
$("#txtAcrescimo").val(1);
//aumenta acrescimo
$("#aumentaAcrescimo").click(function () {
var acrescimo = parseInt($("#txtAcrescimo").val());
if (acrescimo <= 0) {
$("#txtAcrescimo").val(1);
} else {
acrescimo++;
}
$("#txtAcrescimo").val(acrescimo);
});
$("#diminuiAcrescimo").click(function () {
var acrescimo = parseInt($("#txtAcrescimo").val());
if (acrescimo <= 0) {
$("#txtAcrescimo").val(1);
} else if(acrescimo > 1) {
acrescimo--;
}
$("#txtAcrescimo").val(acrescimo);
});
Consegui dessa forma e funcionou, porem começa em 1, tentei aplicar a lógica para começar de zero e não vai.