데이터 행을 반복하는 MVC 5보기 내에 테이블이 있습니다. 각 행은 버튼이 부착 있던 JQuery와JQuery Datatable의 버튼이 JQuery 함수를 호출하지 않습니다.
MVC보기
@foreach (var item Model.MyList) {
//<tr> etc
<td>
<button class="btn btn-danger btn-xs" id="btnDelete" data-toggle="modal" data-target="#myModal" data-id="@item.ID"> Delete </button>
</td>
}
JQuery와
$(document).ready(function() {
//Everytime we press delete in the table row
$('.btn.btn-danger').click(function() {
//Update the text box with delete id so our model knows which one to delete
$('#item-to-delete').val(id);
});
});
를 사용하여 숨겨진 텍스트 상자에 데이터 ID를 통과 할 때 클릭 할 때 그런 다음 여러 가지 이유로 테이블을 https://datatables.net/으로 교체하기로 결정했습니다. 이제 문제는 사용자가 Datatable 내에서 삭제 단추를 클릭하면 JQuery 클릭 함수가 더 이상 호출되지 않으므로 삭제 ID가 숨겨진 텍스트 상자로 전달되지 않는다는 것입니다.
이 사람이 문제를 해결하는 방법에 나를 왜 이런 일 참조하거나 조언을 주시겠습니까 내 DataTable의 스크립트
<script>
$(document).ready(function() {
$('#dataTables-example').dataTable({
"bServerSide": true,
"sAjaxSource": "/MyController/GetAjaxData",
"bProcessing": true,
"bJQueryUI": true,
"aoColumns": [
{ "sName": "ID", "visible": false },
null, //FullName
null, //Email
null, //LastLoginDate
{
"mData": null,
"mRender": function (data, type, full) {
return "<button class='btn btn-danger btn-xs' id='btnDelete' data-toggle='modal' data-target='#myModal' data-id='"+ full[0] +"'>Delete</button>";
}
}
]
});
});
</script>
입니까?
고맙습니다. 대신 $('.btn.btn-danger').click(function()...
에 한번 사용 .on
의