javascript框不显示 - 值

时间:2013-01-24 11:33:31

标签: php javascript html

我想在用户点击按钮时不显示我的负面字符。计数应该以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>

1 个答案:

答案 0 :(得分:2)

把这一行

if(negtive<0)
    negtive = 0;

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

OR

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