猿问

如何让操作更多更少分裂?

我有一个带有复选框和按钮验证的数据表(matricule、salary、number day 和 premium),我想在单击按钮验证时计算总和值,但有一个错误,它为我提供了这个值的 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>

用于检查所有并获取一些值并计算总和的 jQuery 代码:


$(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());



守候你守候我
浏览 183回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答