Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.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 如何使业务更加分散?_Javascript_Jquery - Fatal编程技术网

Javascript 如何使业务更加分散?

Javascript 如何使业务更加分散?,javascript,jquery,Javascript,Jquery,我有一个带有复选框和按钮“验证”的数据表(矩阵、工资、天数和保费),我想在单击按钮“验证”时计算总和值,但它给了我一个关于该值的NaN错误 <table class="table table-bordered" id="mytable"> <tr> <th><input type="checkbox" id="check_all"></th> <th>matricule</th> &l

我有一个带有复选框和按钮“验证”的数据表(矩阵、工资、天数和保费),我想在单击按钮“验证”时计算总和值,但它给了我一个关于该值的NaN错误

<table class="table table-bordered" id="mytable">
  <tr>
    <th><input type="checkbox" id="check_all"></th>
    <th>matricule</th>
    <th>salary</th>
    <th>number day</th>
    <th>premium</th>
  </tr>
  <tr>
    <td><input type="checkbox" class="checkbox"></td>
    <td>1</td>
    <td>5000</td>
    <td>2</td>
    <td><input type="text" name="prime" class="form-control" value="0"></td>
  </tr>
  <tr>
    <td><input type="checkbox" class="checkbox"></td>
    <td>2</td>
    <td>6000</td>
    <td>2</td>
    <td><input type="text" name="prime" class="form-control" value="0"></td>

  </tr>
  <tr>
    <td><input type="checkbox" class="checkbox"></td>
    <td>1</td>
    <td>7000</td>
    <td>1</td>
    <td><input type="text" name="prime" class="form-control" value="0"></td>

  </tr>
</table>
<div class="form-group col-md-offset-5 ">
  <button class="btn btn-success add-all" type="submit" id="hide">Pointage men</button>
</div>

innerText
替换为
text()
,并使用
parseInt
进行计算

$(文档).ready(函数(){
$('check#all')。在('click',函数(e)上{
如果($(this).is(':checked',true)){
$(“.checkbox”).prop('checked',true);
}否则{
$(“.checkbox”).prop('checked',false);
}
});
$('.checkbox')。在('click',function()上{
if($('.checkbox:checked').length==$('.checkbox').length){
$('check'u all').prop('checked',true);
}否则{
$('check'u all').prop('checked',false);
}
});
//显示阵列的jquery代码:
$(“#隐藏”)。单击(函数(){
var项目=[];
$(“tr”)。每个功能(i、r){
如果(i>0&&$(r).find(“输入”).first().prop(“选中”)){
//总额=((工资/24)*nbre)+保费
设sum=((parseInt($(r.cells[2]).text())/24)*parseInt($(r.cells[3]).text())+parseInt($(r.cells[4]).find('input').val());
推({
“矩阵”:r.cells[1]。innerText,
“工资”:r.cells[2]。innerText,
“nbre”:r.cells[3]。innerText,
“premium”:$(r.cells[4]).find('input').val(),
“总和”:总和
})
}
});
控制台日志(项目);
});
})

矩阵
薪水
数字日
溢价
1.
5000
2.
2.
6000
2.
1.
7000
1.
尖兵
$(document).ready(function() {
  $('#check_all').on('click', function(e) {
    if ($(this).is(':checked', true)) {
      $(".checkbox").prop('checked', true);
    } else {
      $(".checkbox").prop('checked', false);
    }
  });
  $('.checkbox').on('click', function() {
    if ($('.checkbox:checked').length == $('.checkbox').length) {
      $('#check_all').prop('checked', true);
    } else {
      $('#check_all').prop('checked', false);
    }
  });

  // jquery code for display array :
  $("#hide").click(function() {
    var items = [];
    $("tr").each(function(i, r) {
      if (i > 0 && $(r).find("input").first().prop("checked")) {
        //sum = (((salary/24)*nbre)+premium)
        let sum = ((($(r.cells[2]).innerText / 24) * $(r.cells[3]).innerText) + $(r.cells[4]).find('input').val());

        items.push({
          "matricule": r.cells[1].innerText,
          "salary": r.cells[2].innerText,
          "nbre": r.cells[3].innerText,
          "premium": $(r.cells[4]).find('input').val(),
          "sum": sum
        })
      }
    });
    console.log(items);
  });
})