【问题标题】:issue in radio button if there is in for loop如果存在 for 循环,则在单选按钮中发出问题
【发布时间】:2014-01-17 16:00:20
【问题描述】:

我有

<input type="radio" value="1" name="is_active_<?php echo $v['class_id'] ?>" id="is_active_<?php echo $v['class_id'] ?>" <?php if($v['display_online']==1){ echo ' checked'; }?> >
<label for="is_active_no_<?php echo $v['display_online'] ?>">Yes    </label>
<input type="radio" value="0" <?php if($v['display_online']==0){ echo 'checked'; }?> name="is_active_<?php echo $v['class_id'] ?>" id="is_active_<?php echo $v['class_id'] ?>">
<label for="active_yes_<?php echo $v['display_online'] ?>"> No  </label>

在 for 循环中。 见图片:- 查看 html 输出:-

<input type="radio" id="is_active_47568" name="is_active_47568" checked="checked" value="1">
 <label for="is_active_no_1">Yes    </label>
<input type="radio" id="is_active_47568" name="is_active_47568" value="0">
<label for="active_yes_1">  No  </label>

但是检查不工作是什么问题?

提前致谢。

【问题讨论】:

  • 试试echo checked='checked';
  • 你好@AlirezaFallah 我试过这个,但也没有用。
  • 粘贴此代码生成的 HTML 输出
  • 可能你if的结果是假的!
  • 可能 if($v['display_online']==0) 不正确,因此没有得到检查。检查 phhp 变量的值。

标签: php html radio-button


【解决方案1】:

如果单选按钮的名称相同,即分组,则“选中”仅适用于一个单选按钮...

【讨论】:

  • hello @user1844933 每行有不同的组。
  • 你好@user1844933 html输出有什么问题请告诉我。
猜你喜欢
  • 2020-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多