1

我已经成功使用了这个脚本,但是我已经尝试过并且失败了,以使其在减去传递 0 时停止产生负数..

<script language="javascript" type="text/javascript">
currentvalue = 1;
function setUp() {
document.getElementById("qty").value = currentvalue;
}
function addOne() {
currentvalue++;
document.getElementById("qty").value = currentvalue;
}
function subtractOne() {
currentvalue--;
document.getElementById("qty").value = currentvalue;
}
</script>

<input type="text" name="qty" id="qty" maxlength="12" value="1" title="qyu" class="input-text qty" />
<div onload="setUp()">
<input class="qtyplus" type="button" value="" onClick="addOne()">
<input class="qtyminus" type="button" value="" onClick="subtractOne()">
</div>

任何人都得到了表演在 0 处停止的神奇部分吗?

谢谢!

4

1 回答 1

1

只需在此处添加一个 if 语句即可

这是你的减法函数

function subtractOne() {
    if(document.getElementById("qty").value !== '0') {
currentvalue--;
document.getElementById("qty").value = currentvalue;
    }
于 2012-07-14T19:45:01.177 回答