如何以codeigniter方式更改以下html元素?
<select id="gender" name ="gender">
<option value="val_male" selected="Male">male</option>
<option value="val_female">Female</option>
</select>
<input id="id_ok" type="button" value="OK" class="btn btn-primary v-align">
我尝试了以下内容..但它不正确。 有什么帮助吗?
<?php
$options = array(
'val_male' => 'Male',
'val_female' => 'Female',
);
echo form_dropdown('gender', $options, 'Male');
echo form_button('id_ok', 'OK');
?>
答案 0 :(得分:0)
是的,你可以这样做:
$data = array(
'name' => 'username',
'id' => 'username',
'value' => 'johndoe',
'maxlength' => '100',
'size' => '50',
'style' => 'width:50%'
);
echo form_input($data);
会产生:
<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
答案 1 :(得分:0)
您必须在选定值
中添加关键参数(选项元素的value
)
$options = array(
'val_male' => 'Male',
'val_female' => 'Female',
);
echo form_dropdown('gender', $options, 'val_male');
答案 2 :(得分:0)
<?php
$options = array(
'val_male' => 'Male',
'val_female' => 'Female',
);
echo form_dropdown('gender', $options, 'val_male');
echo form_button('id_ok', 'OK');
?>
在使用表单方法之前不要忘记加载form_helper