<div class="col-md-11 col-sm-10 col-xs-12 pd-le0 pd-ri0">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group ">
<label class="control-label col-md-4 col-sm-4 col-sm-12" title="Which Key Person does the following information apply to?">Key ID</label>
<div class="col-md-8 col-sm-8 col-xs-12">
<?php /*Previos Entries :- $ValueTax['Person_id']*/
//print_r ($optionkey);exit;
echo form_dropdown('key_id['.$key.']', $optionkey,"",array('class'=>'form-control KeypeopleId','id'=>'Person_id['.$key.']','onchange'=>'addKeypeople(this.options[this.selectedIndex].text)'));
?>
</div>
</div>
v 您好,我在上面的代码中遇到问题。 问题是当我要选择下拉列表时,表单没有出现,并且在单击下拉菜单后无法在表单中前进
"$optionkey"来自这里
<?php
$options = array(
'0'=>'No',
'1'=>'Yes',
);
$option="";
foreach($options as $key=>$value){
$option .="<option value=".$key.">".$value."</option>";
}
$optionkeys="";
foreach($optionkey as $key=>$value){
$optionkeys .="<option value=".$key.">".$value."</option>";
}
?> 这是我的模型,我从哪里获取Keyid
function get_key_people($user_id){
//print_r ($user_id);exit;
$this->db->select('Key_Person_ID,Key_ID');
$this->db->from('key_people');
$this->db->where('user_FK',$user_id);
$this->db->where('is_delete',0);
$result=$this->db->get()->result_array();
$ar=array(''=>"Select",'ADDNEW'=>"ADD NEW");
foreach($result as $key=>$value){
$ar[$value['Key_Person_ID']]=$value['Key_ID'];
}
return $ar;
}
这是怎么回事?
你不需要自己处理$optionkey。在 CI 中,form_dropdown函数会自动添加<select></select>
和<option></option>
标记。
form_dropdown([$name = ''[, $options = array()[, $selected = array()[, $extra = '']]]])
$name (string) -- Field name
$options (array) -- An associative array of options to be listed
$selected (array) -- List of fields to mark with the selected attribute
$extra (mixed) -- Extra attributes to be added to the tag either as an array or a literal string
此函数位于''系统''帮助程序''form_helper.php手册:https://codeigniter.com/user_guide/helpers/form_helper.html