아래 코드는 Ajax 호출을 사용하여 동적으로 생성되고 studentresults이라는 하드 코드 된 div에 배치됩니다.JQuery에서 동적으로 생성 된 데이터에서 click 이벤트 받기
<div id="studentresults" class="row span8 offset2">
<table id="tablestudent" class="table table-striped table-hover center-table">
<thead>Heading for my table</thead<
<tbody>
<tr id="showstudents">
<td>29041</td>
<td>jan</td>
<td>jan</td>
<td>
<a class="btn" href="#">View Results »</a>
</td>
<td id="29041">
<a id="29041" class="btn showstudent" href="#">Delete Student » </a>
</td>
</tr>
<tr id="showstudents">
.... another dynamic record from Ajax...
</tr>
</tbody>
</table>
</div>
잘 작동합니다. 그러나 Delete Student 태그에 대한 또 다른 Ajax 호출을 원합니다. 이 동적 인 내용을 위해 jQuery 클릭 함수를 작성하는 방법을 이해할 수 없습니다.
JQuery와 통화 그러나이 하드 코딩 사업부에서 작동
$('.showstudent').click(function(){
alert('In click');
});
작동하지 않습니다 내가 동적의 경우 동적 <a>
내용
동일한 ID를 가진 요소가 여러 개 있습니다. 그것은 유효한 HTML이 아니므로 id로 요소를 안전하게 선택할 수 있도록 수정해야합니다. – Paulpro