检查单选按钮不在表内工作

时间:2014-10-02 14:17:29

标签: php html twitter-bootstrap radio-button

<table class="table table-bordered table-striped">
        <tr>
            <th></th>
            <th>Excellent</th>
            <th>Satisfactory</th>
            <th>Unsatisfactory</th>
            <th>Poor</th>
        </tr>
        <tr>
            <?php 
                $empty = false;
                $x = 1 ;
                while($x<=4)
                {
                    if($Comments['Preparation']==$x)
                    {
                        $empty = true;
                    }
                    $x++;
                }
            ?>
            <td><b>Preparation</b>- Applicant has prepared his/her himself for the interview and the necessary documents.</td>
            <td><input type="radio" name="Preparation" value="4" <?php if($Comments['Preparation']=='4') {echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}?>></td>
            <td><input type="radio" name="Preparation" value="3" <?php if($Comments['Preparation']=='3') {echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}?>></td>
            <td><input type="radio" name="Preparation" value="2" <?php if($Comments['Preparation']=='2') {echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}?>></td>
            <td><input type="radio" name="Preparation" value="1" <?php if($Comments['Preparation']=='1') {echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}?>></td>
        </tr>
        <tr>
        </tr>
        </table>

我正在尝试预先选择表格中的单选按钮,因为我想显示它。 if语句表示我是否会回显“已检查”。我一直在桌子外面使用它,它工作正常。 是否可以在表格中使用单选按钮?

有什么问题?

4 个答案:

答案 0 :(得分:2)

而不是{echo "Checked=''";} else if($empty) {echo "Disabled=''";}

它应该是 {echo "checked";} else if($empty) {echo "disabled";}

checked=checked等不是表单如何处理收音机的检查方式,它只是

<input type="radio" value="radio_value" checked name="radio_name">
                                        ^^^^^^^

而不是

<input type="radio" value="radio_value" checked=checked name="radio_name">
                                        ^^^^^^^^^^^^^^^

这就是你现在正在做的事情。

同样适合disabled

<input type="radio" value="radio_value" disabled name="radio_name">
                                        ^^^^^^^^

或者您可以设置预定义的变量:

$disabled = 'disabled';

$checked = 'checked';

然后动态地进行

{echo $checked;} else if($empty) {echo $disabled;}


根据你的编辑:

{echo "checked='checked'";} else if($empty) {echo "disabled='disabled'";}

将其更改为

{echo "checked";} else if($empty) {echo "disabled";}

或如上所述,并使用可随时更改的变量。

答案 1 :(得分:1)

不要回显"checked=''""disabled=''",而是将其更改为"checked='checked'""disabled='disabled'"。另外,什么是$empty

答案 2 :(得分:0)

<?php if($Comments['Preparation']=='4') {echo "checked='checked'";} ?>

答案 3 :(得分:0)

<td><input type="radio" name="Preparation" value="4" <?php if($Comments['Preparation']=='4') {echo "checked";} else if($empty) {echo "disabled";}?>></td>
            <td><input type="radio" name="Preparation" value="3" <?php if($Comments['Preparation']=='3') {echo "checked";} else if($empty) {echo "disabled";}?>></td>
            <td><input type="radio" name="Preparation" value="2" <?php if($Comments['Preparation']=='2') {echo "checked";} else if($empty) {echo "disabled";}?>></td>
            <td><input type="radio" name="Preparation" value="1" <?php if($Comments['Preparation']=='1') {echo "checked";} else if($empty) {echo "disabled";}?>></td>

谢谢你们帮助我。我已经解决了这个问题。

相关问题