duan35557593 2014-04-30 06:26
浏览 196
已采纳

如何从复选框更改复选框的属性?

Hi guys im a newbie on php & mysql. I would like to ask how to change checkbox's property from unchecked to checked from a single checkbox. For this case i am displaying the query from my database and i want to have some function like an email's inbox that once we check the control checkbox all the checkboxes in the row will be checked also.

Thank you in advance...

By the way, here is my code in php and java script,

<script>
  $(function () {
    $("#checkAll").click(function () {
        if ($("#checkAll").is(':checked')) {
            $(".select").prop("checked", true);
        } else {
            $(".select").prop("checked", false);
            }
        });
    });
  </script>

Then php code:

error_reporting (E_ALL ^ E_NOTICE);
        if(isset($_POST['department'])){
                    $department=$_POST['department'];
                    $course=$_POST['course'];
                    $level=$_POST['level'];

                    if ($department=="0"){
                        echo "Please select Department!";
                    }else if (($department!="0")&&($course=="0")&&($level =='0')){
                        $query = "SELECT* FROM studaccnt WHERE dept='$department' ORDER BY fname asc";
                        $result = mysql_query($query,$link)
                            or die ("Invalid query".mysql_error());
                        echo "<table border=0 align=center style='table-layout:fixed'>";
                        echo "<tr align = center bgcolor = '#A9F5FE' >";
                        echo "<td width=35><input type='checkbox' name='checkAll' id='checkAll' title='select all'>
                                <td width=100><strong>Family Name</strong></td><td width=100><strong>Given Name</strong></td>";
                        echo "</td><td width=30><strong>M.I.</strong></td>";
                        echo "<td width=160><strong>Department</strong> </td>";
                        echo "<td width=100><strong>Program</strong> </td>";
                        echo "<td width=30><strong>Level</strong> </td>";
                        echo "<td width=100><strong>Contact Number</strong> </td>";
                        echo "<td width=300><strong>Present Address</strong> </td>";
                        "</tr>"; 
                        while ($row = mysql_fetch_array($result,MYSQL_BOTH))
                        {
                                $msgcode=$row["studid"];
                                $message=$row["fname"];
                                //echo "<td width=230><a href=editmsg.php?cmd=edit&msgcode=$msgcode><strong>$row[3]</strong>";
                                //echo "<td width=330><a href=editmsg.php?cmd=edit&msgcode=$msgcode>$row[5]";
                                echo "<tr class=btnav style='table-layout:fixed' bgcolor='#E0FFC1' onmouseover=style.backgroundColor='#CCFF99';
                                        onmouseout=style.backgroundColor='#E0FFC1'>";
                                echo "<td width=50 align=center><input type='checkbox' name='select' value='checkbox'>";  
                                echo "<td width=40>$row[1]";
                                echo "<td width=40>$row[2]";
                                echo "<td width=30 align=center>$row[3]";
                                echo "<td width=150>$row[4]";
                                echo "<td width=80>$row[5]";
                                echo "<td width=40 align=center>$row[6]";
                                echo "<td width=130 align=center>$row[7]";
                                echo "<td width=200>$row[8]";
                                echo "</tr>";
                                }
                                echo "</table>";
                            $rows = mysql_num_rows($result);
                    }
  • 写回答

1条回答 默认 最新

  • douci1196 2014-04-30 07:27
    关注


    You can try using JQUERY, put this in your head tag :

    <head>
    <script src="jquery-1.11.0.min.js"></script>
    </head>
    

    Then below your head, to set Checked:

    function setChecked(string checkbox)
       {
            $("#" + checkbox).prop('checked', true);
       }
    

    to Uncheck:

    function setChecked(string checkbox)
       {
            $("#" + checkbox).prop('checked', false);
       }
    

    Call these methods in your PHP.

    Good luck.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题