检查时,jQuery abs的值设置为2

时间:2016-10-13 17:50:14

标签: javascript jquery

Working jsfiddle

jQuery / javacript仍然是新手,但我有2个函数在检查时总结隐藏值,我需要生成它们差异的绝对值:

$(document).ready(function() {

  function sumRows() {
    var sum = 0,
      total = $('#total');
    $('#myteam tr').each(function() {
      var amount = $(this).find('input[name="amount"]'),
        checkbox = $(this).find('input[name="include"]');
      if (checkbox.is(':checked') && amount.val().length > 0) {
        sum += parseInt(amount.val(), 10);
      }
    });
    total.text(sum);
  }

  function sumRows2() {
    var sum2 = 0,
      total2 = $('#total2');
    $('#otherteam tr').each(function() {
      var amount2 = $(this).find('input[name="amount2"]'),
        checkbox2 = $(this).find('input[name="include2"]');
      if (checkbox2.is(':checked') && amount2.val().length > 0) {
        sum2 += parseInt(amount2.val(), 10);
      }
    });
    total2.text(sum2);
  }

  $('input[name="amount"], input[name="include"]').on('change keyup blur', sumRows);
  $('input[name="amount2"], input[name="include2"]').on('change keyup blur', sumRows2);

});`

这是一个更简单的HTML来向您展示我想要做的事情,我希望差异能够显示每个团队的一个框被选中:

<table>
  <tr>
    <td colspan="2">Difference:
      <span id="diff">0</span>
    </td>
  </tr>
  <tr>
    <td>My Team:
      <span id="total">0</span>
    </td>
    <td>Other Team:
      <span id="total2">0</span>
    </td>
  </tr>
  <tr>
    <td>
      <table id="myteam">
        <tr>
          <td>
            <input type="hidden" value="100" name="amount">
          </td>
          <td>
            <input type="checkbox" name="include">
          </td>
        </tr>
        <tr>
          <td>
            <input type="hidden" value="200" name="amount">
          </td>
          <td>
            <input type="checkbox" name="include">
          </td>
        </tr>
        <tr>
          <td>
            <input type="hidden" value="300" name="amount">
          </td>
          <td>
            <input type="checkbox" name="include">
          </td>
        </tr>
      </table>
    </td>
    <td>
      <table id="otherteam">
        <tr>
          <td>
            <input type="hidden" value="100" name="amount2">
          </td>
          <td>
            <input type="checkbox" name="include2">
          </td>
        </tr>
        <tr>
          <td>
            <input type="hidden" value="200" name="amount2">
          </td>
          <td>
            <input type="checkbox" name="include2">
          </td>
        </tr>
        <tr>
          <td>
            <input type="hidden" value="300" name="amount2">
          </td>
          <td>
            <input type="checkbox" name="include2">
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

1 个答案:

答案 0 :(得分:0)

<tx:annotation-driven proxy-target-class="true" transaction-manager="txManager" />
    <bean id="txManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>