我有一个表单,在该表单中是一个触发模式出现的按钮。在我的模态里面是数据表。我用ajax填写每一行。现在我想为单选按钮添加一列并获取其值并将其传递给父窗口。我怎么做的?
<script>
var table;
$('#list_user').on('show.bs.modal', function (event) {
// alert("hi");
var button = $(event.relatedTarget) // Button that triggered the modal
$.ajax({
url: "<?php echo site_url('Account/getAllUsers')?>",
dataType: 'JSON',
success: function(result){
var modal=$(this);
// var response = $.parseJSON(result.contents);
//clear the table to remove cloned rows
if (table) table.clear();
//reinitialise the dataTable
table = $('#records_table').DataTable({
destroy: true,
bLengthChange: false,
// paging: true
dom: 'frtp'
});
$('#records_table').on( 'click', 'tr', function () {
$('#list_user').modal('hide')
});
$.each(result, function(i, item) {
console.log("inserting", item);
table.row.add([
item.user_id,
item.user_name
]).draw();
});
}
});
});
</script>
&#13;
<div class="container" >
<div class="row">
<div class="modal fade" id="list_user" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="form-horizontal">
<div class="modal-header">
<button class="btn btn-primary close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 id="hdrmsg">List of Users</h4>
</div>
<div class="modal-body">
<div class="welll">
<table class="table table-bordered table-striped table-condensed table-responsive" id="records_table">
<thead class="header">
<tr class="well">
<th>ID #</th>
<th>Name</th>
</thead>
<tbody style="overflow: scroll">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
&#13;