当我试图检查引导单选按钮时,我正在比较2个变量。我完全100%确定相等,但按钮未标记为已选中。 这可能是什么问题?
echo '<label class="btn btn-secondary"><input type="radio" id="bedrijf" name="bedrijf" value="'.$value.'" ';
if($row_list['bedrijf'] == $value) {
echo 'checked ';
}
echo 'autocomplete="off" onclick="validate_add()" onmousemove="validate_add()"><img src="images/logo_'.$value.'_small.png" height="30"></label>';
HTML输出
<div class="form-group btn-group" data-toggle="buttons"><label class="btn btn-secondary"><input type="radio" id="bedrijf" name="bedrijf" value="mb" autocomplete="off" onclick="validate_add()" onmousemove="validate_add()"><img src="images/logo_mb_small.png" height="30"></label><label class="btn btn-secondary"><input type="radio" id="bedrijf" name="bedrijf" value="thure" checked autocomplete="off" onclick="validate_add()" onmousemove="validate_add()"><img src="images/logo_thure_small.png" height="30"></label><label class="btn btn-secondary"><input type="radio" id="bedrijf" name="bedrijf" value="torza" autocomplete="off" onclick="validate_add()" onmousemove="validate_add()"><img src="images/logo_torza_small.png" height="30"></label></div>
答案 0 :(得分:0)
autocomplete
关键字前面需要一个空格。目前,它呈现为... checkedautocomplete="off" onclick="...
。
您还可以按如下方式内联if语句:
echo '<label class="btn btn-secondary">
<input type="radio" id="bedrijf" name="bedrijf" value="'.$value.'" '.($row_list['bedrijf'] == $value ? 'checked' : '').' autocomplete="off" onclick="validate_add()" onmousemove="validate_add()">
<img src="images/logo_'.$value.'_small.png" height="30">
</label>';