У меня есть таблица с большим количеством данных, и по некоторым причинам индекс input
после каждого <td> </td>
продолжает сбрасываться. Для этого я создал эту функцию
$('.custom-input').each(function(index) {
$(this).attr('data-index', index);
});
Но на "функции изменения", когда я пытаюсь ее использовать, она не работает.
Мой текущий код:
$('.custom-input').each(function(index) {
$(this).attr('data-index', index);
});
$('.custom-input[data-index=" '+index+' "]').on('change', function() {
alert($(this).index());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<tr>
<td>
<input class="custom-input" type="text" value="0">
<input class="custom-input" type="text" value="0">
<input class="custom-input" type="text" value="0">
</td>
<td>
<!-- The index for the next input should not be reset -->
<input class="custom-input" type="text" value="0">
<input class="custom-input" type="text" value="0">
<input class="custom-input" type="text" value="0">
</td>
</tr>