我使用jQuery遇到多个输入计数问题。当我用条形码读取它时,在下面形成新的输入,并且计数器正在增加。但是当我删除其中一个时,计数器没有给出正确的数字。
我想:当我删除输入时,刷新所有输入计数。
我的小提琴:fiddle
我的代码:
$('#giris').keypress(function(e){
if (e.which == 13) {
$ney = $(this);
var neymis = $ney.val();
if (neymis != '' || neymis != NULL) {
var wrapper = $('.listele');
var say = $( "#inputsay input" ).size();
wrapper.append('<tr id="in_'+say+'"><td>'+say+'</td><td><input class="form-control input-sm duz'+say+' lan" type="text" value="'+neymis+'" name="mlzm[]" id="in_'+say+'" data-id="'+say+'" disabled="true"></td><td><button class="btn btn-primary btn-sm btn-block" id="sil" data-id="'+say+'">Remove</button></td></tr>');
$('#giris').val('');
$('#say').html(say);
}
}
});
$( document ).on( 'click', '#sil', function () {
var sil_id = $(this).data("id");
var silinen = $(".duz"+sil_id).val();
$("#in_"+sil_id).remove();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="inputsay">
<input class="form-control input-lg" type="text" id="giris" placeholder="Seri no.." ng-keydown="keydown($event)">
<div class="table-responsive mb-lg">
<table class="table table-bordered mb-none">
<thead>
<tr>
<th>#</th>
<th>Serial Num.</th>
<th>Delete</th>
</tr>
</thead>
<tbody class="listele"></tbody>
</table>
</div>
</div>
&#13;
答案 0 :(得分:0)
var say = $(“input”)。size() - 2;
//buşekildeyapacağınainputlarabir class ver
var say = $(“。input_class”)。length
// yaparsan eklemeveçıkarmadaherzamandoğrusonucualırsın