• 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>

  • 相关阅读:
    SQLServer之创建表值函数
    SQLServer之创建标量函数
    SQLServer之函数简介
    SQLServer之创建分布式事务
    SQLServer之创建隐式事务
    SQLServer之创建显式事务
    SQLServer之事务简介
    SQLServer之删除存储过程
    geoserver 添加图层数据
    geoserver入门
  • 原文地址:https://www.cnblogs.com/gerry/p/7562777.html
Copyright © 2020-2023  润新知