我得到了一个代码,一旦用户选择直到第三个复选框,就会禁用复选框。感谢他,我给了他这个代码的功劳。但是,似乎我需要刷新页面才能看到代码在运行。就像我已经选择直到第三个复选框一样,我仍然可以选择第四个,依此类推,直到我刷新它。有没有办法在我选择第3个复选框后禁用它?
请参阅foreach部分了解我的禁用代码
$query="SELECT abc.*
FROM (".$selector.")abc
WHERE
abc.studentname LIKE :q OR
abc.matricno LIKE :q OR
abc.title LIKE :q OR
abc.year LIKE :q OR
abc.thesis_level LIKE :q OR
abc.programme LIKE :q OR
abc.serialno LIKE :q
LIMIT ".$startrow.",".$limitrow;
$stmt = $db->prepare($query);
$stmt->bindValue(':q','%'.$q.'%');
$stmt->bindValue(':e',$e);
$stmt->execute();
$startPage = ($pageno <5) ? 1 : $pageno -4;
$endPage = 8 + $startPage;
$endPage = ($maxpage < $endPage) ? $maxpage : $endPage;
$diff = $startPage - $endPage + 8;
$startPage -=($startPage - $diff > 0) ? $diff : 0;
$a = $startPage;
echo "<ol id='olpoint'>";
if($startPage > 1) echo "<a href='#' onclick='ajaxSearchUpdater(1);'><li>First</li></a>";
while($a<=$endPage){
echo "<a href='#' onclick='ajaxSearchUpdater(".$a.");' style='text-decoration:none;'><li ";
if($pageno == $a){
echo "style='color:grey;font-size:medium;'";
}
echo ">".$a."</li></a>";
$a++;
};
if($endPage < $maxpage) echo "<a href='#' onclick='ajaxSearchUpdater(".$maxpage.");'><li>End</li></a>";
echo "</ol>";
if($stmt->rowCount() > 0){
$r=$stmt->fetchAll();
echo "<table class='tablesorter-blackice' id='myTable' style='width:97%; table-border: 1'>";
echo "<thead>";
echo "<tr>";
echo "<th>No.</th>";
echo "<th>No.Matric</th>";
echo "<th>Name</th>";
echo "<th>Programme</th>";
echo "<th>Title</th>";
echo "<th>Thesis Level</th>";
echo "<th>Serial Number</th>";
echo "<th>Availability</th>";
echo "<th>Select book (Max 3)</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
if(isset($_SESSION['sBorrow']))
$arraynosiri = $_SESSION['sBorrow'];
else
$arraynosiri = array();
$countses = count($_SESSION['sBorrow']);
foreach($r as $row){
echo "<tr align='center'><td>". ($startrow+1) ."</td><td>". $row['matricno'] ."</td><td>". $row['studentname'] ."</td><td>". $row['programme'] ."</td><td>". $row['title'] ."</td><td>". $row['thesis_level'] ."</td><td>". $row['serialno'] ."</td><td>". $row['bavailable'] ."</td><td>
<form method='post'>";
if($key = array_search($row['serialno'], $arraynosiri) !== false) {
$checkbox = "checked";
}
else{
$checkbox = "";
}
if($countses > 1){
echo "<script>
var checkboxes = $('.sBorrow').not(':checked');
$.each(checkboxes, function(idx, cb) {
$(cb).attr('disabled', 'disabled');
});
</script>";
}
else{
echo "<script>
$(cb).attr('disabled', false)
</script>";
}
if($row['bavailable'] == "Available"){
echo "<input type='checkbox' name='sBorrow' id='sBorrow' class='sBorrow' value='". $row['serialno'] ."' ".$checkbox.">
</form></td></tr>";
}
else{
echo "<input type='checkbox' name='sBorrow' id='sBorrow' class='sBorrow' value='". $row['serialno'] ."' ".$checkbox." style='color: grey;' disabled>
</form></td></tr>";
}
$startrow++;
//echo $row['education_level'];
}
echo "</tbody>";
echo "</table>";
}
到目前为止我正在使用此选项复选框时重新加载页面。但是,如果我这样做,问题是,当我在第二页或更多像任何其他页面,一旦它刷新它将返回到第一页。不是很烦人。我的数据清单太多了。
请参阅我的location.reload方法的最底部代码。
function ajaxSearchUpdater(p){
$("#result").show();
var x = $("#search").val();
var y = $("#edulevel").val();
var pagelim = $("#pagefpe").val();
var pagenumber = p;
var checkb = $(".sBorrow").val()
$.ajax({
type:'POST',
url:'userres.php',
data:'q='+x+'&e='+y+'&pagelim='+pagelim+'&pageno='+pagenumber+'&checkb='+checkb,
cache:false,
success:function(data){
$("#result").html(data)
}
});
}
function setsession(sessionid,action){
$("#totalselection").show();
$.ajax({
type:'POST',
url:'test.php',
data:'sBorrow='+sessionid+'&action='+action,
cache:false,
success:function(data){
var out = "<p align='center' style='text-decoration:none;color:white;'>Total Selection: "+data+"<br/>Click here to submit your request <a href='borrowform.php?subid=borrow' id='submitborrow' name='submitborrow' style='text-align:center;'><input type='button' value='REQUEST' id='submitborrow' name='submitborrow'></a> || Click here to clear the selection <a href='#' style='text-align:center;'><input type='button' value='CLEAR'></a></p>";
$("#totalselection").html(out)
}
});
}
$(document).ready(function(e) {
ajaxSearchUpdater(1); // fires on document.ready
$("#search").keyup(function() {
ajaxSearchUpdater(1); // your function call
});
$("#edulevel").click(function() {
ajaxSearchUpdater(1); // your function call
});
$("#pagefpe").click(function() {
ajaxSearchUpdater(1); // your function call
});
$(document).delegate('.sBorrow', 'change', function(){
var sBorrowClass = $(this).attr('class');
var sBorrowValue = $(this).attr('value');
var sBorrowName = $(this).attr('name');
var sBorrowChecked = $(this).attr('checked');
var checked = this.checked;
if(checked){
setsession(sBorrowValue, "SET");
location.reload();
}
else{
setsession(sBorrowValue, "UNSET");
}
})
});