Javascript 如何将选择选项值从php代码传递到Jquery?

Javascript 如何将选择选项值从php代码传递到Jquery?,javascript,php,jquery,codeigniter,Javascript,Php,Jquery,Codeigniter,单击“添加行”按钮时,新行将添加到特定表中。所以我需要添加一个带有php选项值的select选项 如何将这个php值传递给jQuery Jquery函数 我需要在rowData.push中显示select选项 $('.dt-add').each(function () { var whichtable = $(this).parents('form').attr('data-id'); $(this).on('click', function(evt){

单击“添加行”按钮时,新行将添加到特定表中。所以我需要添加一个带有php选项值的select选项

如何将这个php值传递给jQuery

Jquery函数 我需要在rowData.push中显示select选项

  $('.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">&#xf00d;</i></button>');
            table.row.add(rowData).draw( false );
        });
    });

将select元素放入表单中,并将表单提交到一个PHP页面。当我给出最新版本的PHP时,它现在就可以工作了$i$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(); }
$('.dt-add').each(function () {
    var whichtable = $(this).parents('form').attr('data-id');
    $(this).on('click', function(evt){
        var rowData = [];
        var table = $('#teammembertable' + whichtable).DataTable();
        rowData.push('<select class="form-control addstafftype" id="addstafftype" name="addstafftype">'+
            '<option value="">Select</option>'+
            '<?php foreach($selectallstaff as $staffname){ ?>'+
                '<option value="<?php $staffname["Staff_id"]; ?>"><?php $staffname["Staff_name"]; ?></option>'+
            '<?php } ?>'+
            '</select');
        rowData.push('<button type="button" data-id='+ whichtable +' class="btn-xs dt-delete dt-deletes"><i style="font-size:10px" class="fa">&#xf00d;</i></button>');
        table.row.add(rowData).draw( false );
    });
});