0

我希望在用户单击 - 按钮时不显示我的负面角色。计数应以 0 结束。现在也显示 -1、-2、-3 字符。我只想显示 0 或多于 0

<script type="text/javascript" >                                
            function plus(){
                var addplus = 1;
                var plus = document.getElementById('qty').value;
                addplus = parseInt(addplus) + parseInt(plus); 
                document.getElementById('qty').value = addplus;
            }
            function negtive(){
                var neg;
                var negtive = 1;
                var negtives = document.getElementById('qty').value;
                negtive = parseInt(negtives) - parseInt(negtive);               
                document.getElementById('qty').value = negtive;             
            }
        </script>
4

1 回答 1

2

把这条线

if(negtive<0)
    negtive = 0;

negtive = parseInt(negtives) - parseInt(negtive); 

或者

document.getElementById('qty').value = ((negtive <0)?0:negtive );     
于 2013-01-24T11:38:03.063 回答