Home  >  Q&A  >  body text

jquery 如何即时加减计算?

购物后台,管理员修改时候丕想一个一个修改,所以批量进行加减计算,

例子:


<input type="text" value="0">

点击计算器加 value 是1, 点击计算器减 value 是-1

那么另一个购物金额input 值是100, 要是按加1  下面100值变101,要是按减-1 下面100变成99

计算器:


<input type="text" value="0">



购物金额:
<input type="text" value="100">

如何实现??

phpcn_u747phpcn_u7472771 days ago1070

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 00:22:50

    jquery How to perform addition and subtraction calculations in real time? -PHP Chinese website Q&A-jquery How to perform instant addition and subtraction calculations? -PHP Chinese website Q&A

    Let’s take a look and learn.

    reply
    0
  • 阿神

    阿神2017-02-18 13:17:03

    因为用的js里的获取兄弟结点的方法,所以加减两个函数可以重复使用

    <script type="text/javascript">
        function testAdd(){        var aa=document.getElementById("aa");        var bb=document.getElementById("bb");
            a=parseInt(aa.value);
            b=parseInt(bb.value);
            b=b+a;
            bb.value=b;
            bb.innerHTML=bb.value;
        }    function testSub(){        var aa=document.getElementById("aa");        var bb=document.getElementById("bb");
            a=parseInt(aa.value);
            b=parseInt(bb.value);
            b=b-a;
            bb.value=b;
            bb.innerHTML=bb.value;
        }</script><body>
        <input type="button" name="add" value="add" onclick="testAdd()">
        <input type="text" id="aa">
        <input type="button" name="sub" value="sub" onclick="testSub()">
        <br/>
        购物车    <input type="text" value="100" id="bb"></body>

    reply
    1
  • Cancelreply