使用加号(+)在Keyup功能中不起作用

时间:2018-09-10 04:20:44

标签: javascript

所有设置都很好,但是请在这里看到工资的增加,它将工资的值作为html添加到最后一次计算中(我认为这是因为加号(+),因为javascrip使用它来添加两个html值)

html代码:html代码是完美的,只需要关注php代码

 <div id="addPart1" class="hide/row r/iow" style="line-height:35px; width:100%;margin:auto; min-width:800px;float:left;padding-left:20px; font-size:120%">

    <div  style="display:inline-block; width:14%">

    <input class="form-control" style="width:100%; height:30px" name="c_v[]" list="browsers" >
    <datalist id="browsers">


     <?php include 'f_select_account.php'; ?></div>


    <div  style="display:inline-block; width:14%">

    <input class="form-control" style="width:100%; height:30px" name="item[]" list="browsers" >
    <datalist id="browsers">

    <?php include 'f_select_account.php'; ?></div>

    <div  style="display:inline-block; width:14%">

  <select id="selectID1" name="usi" class="chosen-select form-control" required style="height:25px; font-size:80%">


    <?php include 'f_select_users_emp.php'; ?></div>

      <div  style="display:inline-block; width:17%"><input style="height:30px;margin-left:0px" class="form-control" type="text" id="descID1" name ="item_note[]"  form="partForm"></div>




      <div  style="text-align:right; display:inline-block; width:7%"><input  style="text-align:right; height:30px"  class="form-control coll" type="text" id="collID1" name="amount[]" form="partForm"></div>
      <div  style="text-align:right; display:inline-block; width:7%"><input  style="text-align:right; height:30px"  class="form-control per" type="text" id="perID1" name="amount[]" form="partForm"></div>
                <div  style="text-align:right;display:inline-block; width:7%"><input  style="text-align:right; height:30px"  class="form-control comm" type="text" id="amt1ID" name="amount1[]" form="partForm"></div>

      <div  style="text-align:right; display:inline-block; width:7%"><input  style="text-align:right; height:30px"  class="form-control salary" type="text" id="amtID" name="amount[]" form="partForm"></div>
      <div  style="text-align:right;display:inline-block; width:7%"><input readonly style="text-align:right; height:30px"  class="form-control tamount" type="text" id="amt1ID" name="amount1[]" form="partForm"></div>

      <div  style="display:inline-block; width:2%"><input  STYLE="cursor:pointer; width:100%; text-align:right; font-size:140%; font-weight:bold; border:none; background:none" id="deleteLine1" value="X" /></div>


    </div>



    <div style=" back/ground:whitesmoke; width:100%;margin:auto;padding-left:20px ">
      <a href='javascript:void(0);' STYLE="font-size:140%; text-decoration:none; border:none; background:none; color:brown"  id="addLine">add row <i class="fa fa-plus-square" aria-hidden="true"></i>
        </a>





    </div>

</div>

php代码:此处未将工资问题添加到公式的其余部分...乘法(*)和减号(-)起作用,但加号(+)不能正常起作用..它可以作为htmls值加法。

 $('body').delegate('.coll,.per,.comm, .salary, 
  .tamount','keyup',function()
                {
                    var tr=$(this).parent().parent();
                    var coll =tr.find('.coll').val();
                    var per =tr.find('.per').val();



                    var amt =(coll * per / 100);



                    tr.find('.comm').val(amt);
                    var salary =tr.find('.salary').val();
                     var tamt =(coll * per / 100 + salary); 

                    tr.find('.tamount').val(tamt);




                });
            });

1 个答案:

答案 0 :(得分:0)

我得到了解决方案,因为加号不起作用,但是其他运算符起作用,所以我使用减号(-)和-1 *(薪水)

var tamt =(coll * per / 100-(salary);

因此它解决了,但需要获取有关为什么加号不起作用以及t不能作为html值起作用的信息。