我有一个表格,我想加所有不等于零 [英] I have a form and i want to add all the is not equal to zero

查看:66
本文介绍了我有一个表格,我想加所有不等于零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想要的输出.我希望date等于1并添加总输入,并且在课堂上有一个额外的x.

This is my desired output. I want the date will be equals to 1 and add in the total input and in class there's an additional x.

<div class="form-group{{ $errors->has('day1') ? ' has-error' : '' }}">
                        <label for="day1" class="col-md-4 control-label">Day 1</label>

                        <div class="col-md-6">
                           <div class='input-group date' id='day1'>
                              <input type='text' class="form-control" name="day1" value="0" readonly="readonly" />
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar">
                                    </span>
                                </span>
                            </div>
                        </div>
                    </div>

推荐答案

嗯,据我所知,您有不同的input字段,并且只希望具有values != 0的字段.您可以使用遍历所有input字段的伪代码,并且只有在value != 0时,您的代码才会执行​​:

Well, as I understand, you have different input fields and you want only those that have values != 0. You can use this pseudo code which traverses thru all input fields and your code will execute only if value != 0:

$('input').each(function() {
  if ($(this).val() != 0) {
    // code goes here...
  }
});

$('input').on('change', function() {
  updateCount();
})

function updateCount() {
  var count = 0;
  $("input:not('.k-textbox')").each(function() {
    if ($(this).val() != 0) {
      count++;
    }
  });
  $(".k-textbox").val(count + 'x');
  console.log(count + 'x');
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1">
  <tr>
    <td>
      <input type='text' name='total[]' id='total1' value='0' />
    </td>
  </tr>

  <tr>
    <td>
      <input type='text' name='total[]' id='total2' value='0' />
    </td>
  </tr>


  <tr>
    <td>
      <input type='text' name='total[]' id='total3' value='0' />
    </td>
  </tr>


  <tr>
    <td>
      <input type='text' name='total[]' id='total4' value='0' />
    </td>
  </tr>



  <tr>
    <td>
      <input type="text" class="k-textbox" value="" style="color: red; text-align: right; font-family: courier" name="total_amt_due" id="amt_due" readonly="readonly" />
    </td>
  </tr>
</table>

这篇关于我有一个表格,我想加所有不等于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆