Vì vậy, tôi có nút này để thêm một hàng mới vào bảng, tuy nhiên vấn đề của tôi là nó không lắng nghe .new_participant_form
sự kiện nhấp chuột nữa sau khi phương thức nối thêm diễn ra.
Nhấp vào Thêm mục nhập mới sau đó nhấp vào tên biểu mẫu.
$('#add_new_participant').click(function() {
var first_name = $('#f_name_participant').val();
var last_name = $('#l_name_participant').val();
var role = $('#new_participant_role option:selected').text();
var email = $('#email_participant').val();
$('#registered_participants').append('<tr><td><a href="#" class="new_participant_form">Participant Registration</a></td><td>'+first_name+ ' '+last_name+'</td><td>'+role+'</td><td>0% done</td></tr>');
});
$('.new_participant_form').click(function() {
var $td = $(this).closest('tr').children('td');
var part_name = $td.eq(1).text();
alert(part_name);
});
});
HTML
<table id="registered_participants" class="tablesorter">
<thead>
<tr>
<th>Form</th>
<th>Name</th>
<th>Role</th>
<th>Progress </th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#" class="new_participant_form">Participant Registration</a></td>
<td>Smith Johnson</td>
<td>Parent</td>
<td>60% done</td>
</tr>
</tbody>
</table>
<button id="add_new_participant"></span>Add New Entry</button>
new_participant_form
phần tử đã có trong tài liệu. Để làm cho nó hoạt động cho các phần tử bạn sẽ thêm sau này, bạn có thể sử dụng ủy quyền sự kiện, như dystroy đã chứng minh hoặc đính kèm trình xử lý vào mỗi neo trước khi bạn chèn nó (cái trước hiệu quả hơn).