zoukankan      html  css  js  c++  java
  • 2016/3/31 ①全选时 下面选项全选中 ② 下面不选中时 全选取消 ③在“” 中 转义字符的使用 onclick="Checkpa(this,'flall')"; ④区别于分别实现 重点在于两种情况合并实现

    testxuanbuxuan.php

      1 <!DOCTYPE html>
      2 <html lang="en">
      3 <head>
      4     <meta charset="UTF-8">
      5     <title>Document</title>
      6 </head>
      7 <body>
      8 <!-- <?php 
      9     @$qytj=$_POST["qy"];
     10     @$zltj=$_POST["zl"];
     11     @$fltj=$_POST["fl"];
     12     @$key=$_POST["key"];
     13 
     14     //造查询字符串
     15     $st1=" 1=1";
     16     $st2=" 1=1";
     17     $st3=" 1=1";
     18     $st4=" 1=1";
     19     //判断第一个条件是否有值
     20     if (count($qytj)>0) {
     21         $ss=implode("','",$qytj);
     22         $st1=" Area in ('$ss') ";
     23     }
     24     //依次判断第二三四个条件
     25     if (count($zltj)>0) {
     26         $zz=implode("','",$zltj);
     27         $st2=" Renttype in ('$zz')";
     28     }
     29     if (count($fltj)>0) {
     30         $ff=implode("','",$fltj);
     31         $st3=" HouseType in ('$ff')";
     32     }
     33     if ($key!="") {
     34         
     35         $st4=" KeyWord like '%$key%'";
     36     }
     37 $sqltj=" where".$st1." and ".$st2." and ".$st3." and ".$st4;
     38 
     39  ?> -->
     40 <form action="hhcheck.php" method="post">
     41 <div>
     42     <div>区域:
     43         <input type="checkbox" id="qyall" name="qyall" onclick="CheckAll(this,'qy')" >全选
     44     </div>
     45     <div>
     46     <?php 
     47         //1.造连接对象
     48         $db=new mysqli("localhost","root","123","test2");
     49         //2.判断是否连接成功
     50         !mysqli_connect_error()or die("连接失败");
     51         $sqlqy="select distinct(Area) from House";
     52         $result=$db->query($sqlqy);
     53         $arrqy=$result->fetch_all();
     54         for ($i=0; $i <count($arrqy); $i++) { 
     55             echo "<div style='display:inline'><input type='checkbox' name='qy[]' class='qy' value='{$arrqy[$i][0]}' onclick="Checkpa(this,'qyall')";>{$arrqy[$i][0]}</div>&nbsp";
     56         }
     57          ?>
     58     </div>
     59     <br>
     60     <div>租赁类型:
     61         <input type="checkbox" id="zlall" name="zlall" onclick="CheckAll(this,'zl')">全选    
     62     </div>
     63         <div>
     64     <?php 
     65         //1.造连接对象
     66         $db=new mysqli("localhost","root","123","test2");
     67         //2.判断是否连接成功
     68         !mysqli_connect_error()or die("连接失败");
     69         $sqlzl="select distinct(Renttype) from House";
     70         $result=$db->query($sqlzl);
     71         $arrzl=$result->fetch_all();
     72         for ($i=0; $i <count($arrzl); $i++) { 
     73             echo "<div style='display:inline'><input type='checkbox' name='zl[]' class='zl' value='{$arrzl[$i][0]}'onclick="Checkpa(this,'zlall')";>{$arrzl[$i][0]}</div>&nbsp";
     74         }
     75          ?>
     76     </div>
     77     <br>
     78     <div>房屋类型:
     79         <input type="checkbox" id="flall" name="fl[]" onclick="CheckAll(this,'fl')">全选
     80     </div>
     81     <div>
     82     <?php 
     83         //1.造连接对象
     84         $db=new mysqli("localhost","root","123","test2");
     85         //2.判断是否连接成功
     86         !mysqli_connect_error()or die("连接失败");
     87         $sqlfl="select distinct(HouseType) from House";
     88         $result=$db->query($sqlfl);
     89         $arrfl=$result->fetch_all();
     90         for ($i=0; $i <count($arrfl); $i++) { 
     91             echo "<div style='display:inline'><input type='checkbox' name='fl[]' class='fl' value='{$arrfl[$i][0]}' onclick="Checkpa(this,'flall')";>{$arrfl[$i][0]}</div>&nbsp";
     92         }
     93          ?>
     94     </div>
     95     <br>
     96     <div>关键字:
     97         <input type="text" name="key">
     98         <input type="submit" value="搜索">
     99     </div>    
    100 </div>
    101 </form>
    102     <table border="1" width=100% cellpadding="0" cellspacing="0">  
    103         <tr>
    104             <td>关键字</td>
    105             <td>区域</td>
    106             <td>面积</td>
    107             <td>租金</td>
    108             <td>租赁类型</td>
    109             <td>房屋类型</td>
    110         </tr>
    111         <?php 
    112         //1.造连接对象
    113         $db=new mysqli("localhost","root","123","test2");
    114         //2.判断是否连接成功
    115         !mysqli_connect_error()or die("连接失败");
    116         $sql="select * from House ".$sqltj;
    117         $result=$db->query($sql);
    118         $arral=$result->fetch_all();
    119         for($i=0; $i<count($arral); $i++){ 
    120             echo "<tr>
    121         <td>{$arral[$i][1]}</td>
    122         <td>{$arral[$i][2]}</td>
    123         <td>{$arral[$i][3]}</td>
    124         <td>{$arral[$i][4]}</td>
    125         <td>{$arral[$i][5]}</td>
    126         <td>{$arral[$i][6]}</td>
    127             </tr>";
    128         }
    129         
    130          ?>
    131     </table>
    132 </body>
    133 <script>
    134     function CheckAll(ck,list)
    135     {    //找到全选按钮的选中状态
    136         var zt=ck.checked;
    137         //找到所有控制的checkbox
    138         var all=document.getElementsByClassName(list);
    139         //控制所有的checkbox状态和全选的状态一致
    140         for (var i = 0; i < all.length; i++) {
    141             all[i].checked=zt;
    142         }
    143     }
    144     function Checkpa(pa,ids)
    145     {
    146         if(!pa.checked)    
    147         {
    148 
    149             document.getElementById(ids).checked=
    150             false;
    151             
    152         }
    153     }
    154 </script>
    155 </html>
    View Code

    图1: 全选中

    图2:有一个不选中,全选取消

  • 相关阅读:
    AJAX 三级联动
    AJAX JSON类型返回
    AJAX 汽车详细信息练习
    JQ AJAX
    对话框关联两个Layout时
    删除,拨打电话,发送短信对话框
    自定义对话框,时间日期对话框
    一般对话框,单选复选对话框
    JAVA。String转Int
    加监听器,单选复选按钮
  • 原文地址:https://www.cnblogs.com/haodayikeshu/p/5340168.html
Copyright © 2011-2022 走看看