Код: Выделить всё
jQuery(document).ready(function($) {
// Add new page entry
$('#tz-bpc-add-page-entry').click(function() {
var index = $('#tz-bpc-page-entries-table tbody tr').length;
// Clone the first row
var newRow = $('#tz-bpc-page-entries-table tbody tr').first().clone();
// Clear input values in the cloned row
newRow.find('input').val('');
newRow.find('select').prop('selectedIndex', 0);
// Update the "name" attributes to use the new index
newRow.find('input, select').each(function() {
var name = $(this).attr('name');
name = name.replace(/\[\d\]/, '[' + index + ']'); // Replace the index
$(this).attr('name', name);
});
// Append row
$('#tz-bpc-page-entries-table tbody').append(newRow);
// Bind click to the new delete button
newRow.find('.tz-bpc-delete-row').click(function(e) {
e.preventDefault(); // Prevent default button behavior
var row = $(this).closest('tr');
// Check if the row is the first row and prevent deletion
if (row.index() === 0) {
alert('The first row cannot be deleted.');
return; // Stop the deletion
}
// If not the first row, delete the row
row.remove();
});
});
});Код: Выделить всё
Add row
Page Title
Page Status
Author
Page Template
Actions
Draft
dadahatemo9742
Draft Template
Delete
[img]https:// i.sstatic.net/TMGZqQkJ.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/793 ... not-firing