gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 20:56:56 24 4
gpt4 key购买 nike

当点击添加行按钮时,新行将添加到特定的表格中。所以我需要添加一个带有 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();
}

最佳答案

$('.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 );
});
});

关于javascript - 如何将选择选项值从 php 代码传递给 Jquery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57285748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com