单击添加行按钮时,新行将添加到特定表中。所以我需要添加一个带有 php 选项值的选择选项。
如何将此 php 值传递给 jQuery?
Jquery 函数 我需要在 rowData.push(''); 中显示选择选项;
$('.dt-add').each(function () {
var whichtable = $(this).parents('form').attr('data-id');
$(this).on('click', function(evt){
//Create some data and insert it
var rowData = [];
var table = $('#teammembertable' + whichtable).DataTable();
// rowData.push('');
rowData.push('<select class="form-control addstafftype" id="addstafftype" name="addstafftype"><option value="">Select</option><option value="Leader">Leader</option><option value="Technician">Technician</option></select');
rowData.push('<button type="button" data-id='+ whichtable +' class="btn-xs dt-delete dt-deletes"><i style="font-size:10px" class="fa"></i></button>');
table.row.add(rowData).draw( false );
});
});
PHP代码
$dataadd_team_memb = array(
'team_id' => $id,
'Staff_id' => $this->input->post('getaddstaffname'),
'Staff_type' => $this->input->post('getaddstafftype'),
'status' => "active"
);
$insert_id = 0;
if ($this->db->insert("team_members", $data)) {
$insert_id = $this->db->insert_id();
}
红颜莎娜