Given the code in the question you're retrieving a value and setting it as the text()
of the .id-label
, you can use the same value and set it as the val()
of your target input:
$(document).ready(function() {
var table = $('#example').DataTable();
$('#example tbody').on('dblclick', 'tr', function() {
let $tr = $(this);
if ($tr.hasClass('selected')) {
$tr.removeClass('selected');
} else {
table.$('tr.selected').removeClass('selected');
$tr.addClass('selected');
$('#classModal').modal('hide');
let targetValue = $tr.find('td:first').text();
$('.id-label').text(targetValue);
$('#label').val(targetValue);
}
});
});
Note that I removed .closest('tr')
as this
refers to the tr
already.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…