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

单击添加行按钮时,新行将添加到特定表中。所以我需要添加一个带有 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">&#xf00d;</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();

    }


慕姐8265434
浏览 144回答 1
1回答

红颜莎娜

$('.dt-add').each(function () {&nbsp; &nbsp; var whichtable = $(this).parents('form').attr('data-id');&nbsp; &nbsp; $(this).on('click', function(evt){&nbsp; &nbsp; &nbsp; &nbsp; var rowData = [];&nbsp; &nbsp; &nbsp; &nbsp; var table = $('#teammembertable' + whichtable).DataTable();&nbsp; &nbsp; &nbsp; &nbsp; rowData.push('<select class="form-control addstafftype" id="addstafftype" name="addstafftype">'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="">Select</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<?php foreach($selectallstaff as $staffname){ ?>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="<?php $staffname["Staff_id"]; ?>"><?php $staffname["Staff_name"]; ?></option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<?php } ?>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</select');&nbsp; &nbsp; &nbsp; &nbsp; 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>');&nbsp; &nbsp; &nbsp; &nbsp; table.row.add(rowData).draw( false );&nbsp; &nbsp; });});
打开App,查看更多内容
随时随地看视频慕课网APP