Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery中的除法运算和求和运算不起作用?_Javascript_Jquery - Fatal编程技术网

Javascript jquery中的除法运算和求和运算不起作用?

Javascript jquery中的除法运算和求和运算不起作用?,javascript,jquery,Javascript,Jquery,我有一个带有复选框的datatable和一个按钮add,我想当我点击按钮add时,控制台显示salaire和prime以及Seld,其计算方式与Seld=salaire/24+prime类似 index.php 这是因为变量salaire和prime实际上在代码中作为字符串返回,因此在执行此操作时: console.log'5000'/24+'100'无法理解您在这里遇到的问题。你能再解释一下吗?@palaѕѕѕѕ我的问题是,当我将salaire/24添加到素数时,它认为素数为空。例如,如果我

我有一个带有复选框的datatable和一个按钮add,我想当我点击按钮add时,控制台显示salaire和prime以及Seld,其计算方式与Seld=salaire/24+prime类似

index.php


这是因为变量salaire和prime实际上在代码中作为字符串返回,因此在执行此操作时:


console.log'5000'/24+'100'无法理解您在这里遇到的问题。你能再解释一下吗?@palaѕѕѕѕ我的问题是,当我将salaire/24添加到素数时,它认为素数为空。例如,如果我这样做,它是计算5000/24+100,结果是208.33,而不是308。333@SokMa我在这里运行了你的示例,得到了308.333。你确定吗?@CaduDeCastroAlves给我208.333而不是308.33
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">


<div id="form2">
<table class="table table-bordered" id="mytable">
  <tr>
    <th><input type="checkbox" id="check_all"></th>
    <th>nom</th>
    <th>salaire</th>
    <th>adresse</th>
    <th>prime</th>
  </tr>
  <tr>
    <td><input type="checkbox" class="checkbox"></td>
    <td>najib</td>
    <td>5000</td>
    <td>tihit</td>
    <td><input type="text" name="prime" class="form-control prime" value="0"></td>
  </tr>
  <tr>
    <td><input type="checkbox" class="checkbox"></td>
    <td>adil</td>
    <td>4000</td>
    <td>tagmast</td>
    <td><input type="text" name="prime" class="form-control prime" value="0"></td>
  </tr>
</table>
<div class="form-group col-md-offset-5 ">
  <button class="btn btn-success " type="submit" id="add">Pointage men</button>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
  $("#add").click(function(){
    var items = [];
    $("tr").each(function(i,r){
        let salaire = r.cells[2].innerText;
        let prime = $(r).find(".prime").val();
        let sold = ((salaire)/24) + prime;
        if ( i > 0 && $(r).find("input").first().prop("checked")){
           items.push({ "salaire" : salaire , "prime" : prime , "sold" : sold });
        }
    })
console.log(items);
  })
})
</script>