donglinxia1541 2018-11-23 05:37 采纳率: 0%
浏览 148

如何选中和禁用复选框?

I have tried:

<input disabled='disabled' 
checked='checked' 
type='checkbox' 
name='checkTema[]' 
value=".$cat->cat_ID."> ".$cat->name."<br>"

But that won't pick up the value when I send the form

UPDATE

Thanks to a comment I've got a helping answer from another SO question, yet I am not sure how I should be applying the trick, tried the following but not sending the value

echo "<input type='hidden' name='checkTema[]' value='1' >";
echo "<input type='checkbox' checked='checked' disabled='disabled' name='checkTema[]' value=".$cat->cat_ID."> ".$cat->name."<br>";
  • 写回答

4条回答 默认 最新

  • dtsi9484 2018-11-23 05:44
    关注

    If you need to POST disabled checkboxes, I suggest using a hidden input before:

    <input type="hidden" name="checkbox_disabled" value="<?php echo $checkbox_value; ?>" /> <== Checked and disabled
    

    Then in your PHP code, you can simply check:

    if ($_POST['checkbox']) {
      //Checkbox wasn't disabled on submission
    } else {
      //Fallback to using the disabled value:
      $disabledVal = $_POST['checkbox_disabled'];
    }
    

    Additionally, you can simply undisable all the elements of the form before submission:

    $('form').submit(function() {
        $(this).find('input').attr('disabled', false);
    });
    

    See this question/answer for more information on how you can alternatively do this.

    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题