选中全部/取消选中所有在Ajax Called Page中无效的Checkbox

时间:2016-07-13 08:06:08

标签: javascript php jquery ajax checkbox

选择所有输入复选框不起作用。 我检查了代码没有ajax调用,然后选择所有复选框是完美的工作。 当选中all all复选框时,将检查while循环内显示的所有复选框。但是当我与主html页面集成时,select all复选框不起作用。 请告诉我需要申请正确使用以下代码选择所有复选框的更改。

HTML页面

  <html>
  <head>
  <script src="js/jquery-1.10.2.min.js"></script>
  <script>
    $(function(){
      $('.parent').on('click', function() {
          var checked = this.checked;
          $(this).parents('table').find('.child').each(function() {
            this.checked = checked;
          });
      });
    });
</script>
</head>
<body>
<form  name="form1" method="post"  enctype="multipart/form-data" action="pras.php" class="form-horizontal" >                                                
<fieldset>
<div class="form-group">
<label for="select111" class="col-md-2 control-label">Select Division</label>
<div class="col-md-10">
<select name="divis" id=division class="form-control" onchange="showUsers(this.value)">                                         

</select>
  </div>
</div>
<div id="txtHint"><b></b></div> 
    <div class="form-group">
        <p align="center"> 
        <input class="btn btn-primary" type="submit" name="submit" value="submit">
        </p>
    </div>
</fieldset>
</form>
<script>
function showUsers(vari) {
if (vari== "" && vari== 0) {
    document.getElementById("txtHint").innerHTML = "";
    return;
} else { 
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","get_user_div.php?&variable="+vari,true);
    xmlhttp.send();
}
}
</script>
</body>
</html>

get_user_div.php

 echo "<table class='table table-bordered'>
<tr>
 <th>Register Number</th>
 <th>Prasent/Abstent </br> Select All <input type='checkbox' name='select1' id='select1' class='parent' />
 </th>
 </tr>";
 while($row = mysql_fetch_array($result)) {
$sql="SELECT * FROM attandance WHERE register_no= '$row[register_no]'";
$res = mysql_query($sql);
$col = mysql_fetch_array($res);
echo "<tr>";
echo "<td>" . $row['register_no'] . "</td>";
echo "<td>
        <input type ='checkbox' name='present[]' value='$row[register_no]' class='child' id='check[]'/>
      </td>";
 echo "</tr>";
}

  echo '</tr>';
  echo "</table>";

0 个答案:

没有答案