zoukankan      html  css  js  c++  java
  • js全局购物车加减全局变量计数

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>安心牧羊人</title>
    </head>
    <body>

    <p>全局变量计数。</p>
    <button type="button" onclick="myFunction1()">-</button>
        <span id="demo" style="color:red;">0</span>
    <button type="button" onclick="myFunction2()">+</button>
        

    <script>

    var counter=0;
        function add() {
            if(counter>=10){  //设置库存最大数例如10以上不能点击加
                return counter += 0;
        }else{
            
           return counter += 1;
            
        }
        return counter += 1;
    }
    function cor() {
       
        if(counter===0){  //设置最小数值不能低于0 ,低于0不能点击
          return counter += 0;
        }else{
            
           return counter += -1;
            
        }
    }
    function myFunction1(){
       
        document.getElementById("demo").innerHTML = cor();
    }
        function myFunction2(){
       
        document.getElementById("demo").innerHTML = add();
    }
    </script>

    </body>
    </html>

  • 相关阅读:
    POJ 1905 Expanding Rods 木棍膨胀
    [JSOI2007] 文本生成器
    18.09.22模拟赛T2 历史
    [USACO18OPEN] Talent Show
    [国家集训队] 整数的lqp拆分
    [HNOI2008] GT考试
    读入优化效果测试
    Trie图 模板
    manacher算法 详解+模板
    [洛谷P4299] 首都
  • 原文地址:https://www.cnblogs.com/gerry/p/7562777.html
Copyright © 2011-2022 走看看