Maison  >  Questions et réponses  >  le corps du texte

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 Il y a quelques jours1072

répondre à tous(2)je répondrai

  • 数据分析师

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

    Comment effectuer des calculs d'addition et de soustraction instantanés avec jquery ? -Site Web chinois PHP Q&A-jquery Comment effectuer des calculs d'addition et de soustraction en temps réel ? - Questions et réponses sur le site Web chinois PHP

    Veuillez regarder et apprendre.

    répondre
    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>

    répondre
    1
  • Annulerrépondre