编辑时如何设置单选按钮的值?
我有一个带有单选按钮的性别行,男性和女性.当我第一次注册时,单选按钮的值将存储在数据库中.现在我的问题是,如果我再次编辑该行,它想要来(这意味着检查)该值作为男性/女性.怎么做?
I have a Gender Row with radio buttons male & female. when i register as first time the values of radio button will store in database. Now my question is if i edit that row again it want to come(that means checked) with that value as male/female. how to make it?
注意:使用 php.
HTML 脚本:
<tr id="inside">
<td align="right" width="40%" id="side" >Gender</td>
<td width="3%"> </td>
<td align="left" width="50%">
<input type="radio" name="sex" value="Male" size="17">Male
<input type="radio" name="sex" value="Female" size="17">Female
</td>
</tr>
推荐答案
填充字段时,可以检查值:
When you populate your fields, you can check for the value:
<input type="radio" name="sex" value="Male" <?php echo ($sex=='Male')?'checked':'' ?>size="17">Male
<input type="radio" name="sex" value="Female" <?php echo ($sex=='Female')?'checked':'' ?> size="17">Female
假设您从数据库返回的值在变量 $sex
Assuming that the value you return from your database is in the variable $sex
选中的属性会预选匹配的值
The checked property will preselect the value that match
相关文章