如果variable = value则勾选复选框

时间:2013-04-16 16:13:18

标签: php html checkbox

    <li>
        Assign Task to Every User? &nbsp; &nbsp; 
        <input type="checkbox" name="display_insert_email" onchange="this.form['email'].hidden=this.checked" />
    </li>
    <li>
        <input type="text" name="email" style="width: 400px;" value="<?php if ($task_member_id > 0){ echo $task_member_email; } else 'Please enter email address of user'?>" onclick="if(this.value=='Please enter email address of user'){this.value=''}" onblur="if(this.value==''){this.value='Please enter email address of user'}" >
    </li>

这两个有问题的区域,如果$project_member_id = 0的值我希望选中复选框..

我已经搜索过,但是我找不到与此相关的任何内容,我可能正在寻找错误的内容,但任何帮助都将不胜感激!

4 个答案:

答案 0 :(得分:1)

<input type="checkbox" <?php if($var == '0'){ ?> checked <?php } ?>/>

答案 1 :(得分:1)

如果条件为真,只需echo checked

<input type="checkbox" value="1" <?php if($val == '1') {echo 'checked';} ?> />

答案 2 :(得分:1)

<input type="checkbox" <?php if($variable == 1){ echo "checked"; } ?> >

答案 3 :(得分:1)

<input type="checkbox" value="1" <?php if($project_member_id == 0) echo 'checked="checked"'; ?> >