Jquery удалить строку не срабатываетJavascript

Форум по Javascript
Ответить
Anonymous
 Jquery удалить строку не срабатывает

Сообщение Anonymous »

Я создаю плагин для массового добавления страниц в WP, но мне нужно удалять строки по мере необходимости. Попытка удалить строку каждый раз при нажатии кнопки удаления, но она не срабатывает. Что я делаю не так?

Код: Выделить всё

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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»