我希望当用户单击-按钮时不显示我的否定字符。计数应以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>

最佳答案

把这行

if(negtive<0)
    negtive = 0;




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


要么

document.getElementById('qty').value = ((negtive <0)?0:negtive );

关于php - javascript框不显示-值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14500389/

10-11 23:51