0
我有一个包含3列的数据表:用户名,电子邮件和角色。 在第3列(角色)的标题中,有一个“编辑”按钮。点击“编辑”后,我希望每行都有下拉菜单。应该隐藏“编辑”按钮,然后出现“保存”按钮。使用下面的代码,我可以添加下拉菜单,但我无法从下拉菜单中选择任何内容。如何在每行数据表中添加下拉列表
<script type="text/javascript">
$(document).ready(
function() {
var oTable = $('#big_table').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": '<?php echo base_url(); ?>index.php/User/datatable',
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ":20,
"oLanguage": {
"sProcessing": "<img src='<?php echo base_url(); ?>assets/images/ajax-loader_dark.gif'>"
},
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 2 ] }
],
"fnInitComplete": function() {
$("#big_table tr").find("th:nth-child(3)").append('<button id = "editTool">Edit</button><button id = "save"> Save </button>');
$("#save").hide();
},
"fnDrawCallback": function() {
},
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
},
'fnServerData': function(sSource, aoData, fnCallback)
{
$.ajax
({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
}
});
$("#big_table").on('click',$("#editTool"),function(){
console.log("editTool click");
console.log("Edit");
$("#big_table tbody tr").each(function(index){
var selected = "Admin1";
var name = "role"+index;
var menu = '<?php
$options = array(
'Student' => 'Student',
'Contributer' => 'Contributer',
'Moderator' => 'Moderator',
'Admin1' => 'Admin 1',
'Admin2' => 'Admin 2',
);
$selected = "'+selected+'";
$val = form_dropdown("'+name+'", $options,"'+selected+'");
echo preg_replace("/\r|\n/","",$val)?>';
$(this).find("td:nth-child(3)").html(menu);
$("#editTool").hide();
$("#save").show();
});
});
});
</script>
你是什么意思“..不能从下拉菜单中选择任何东西?”你有选择框在你想要他们的选项吗? – dcodesmith
是选择框有适当的选项。但我无法选择。 – hsusmita