gpt4 book ai didi

jquery checkoxes 和 php 循环

转载 作者:行者123 更新时间:2023-12-01 07:39:38 24 4
gpt4 key购买 nike

我试图让用户在 php.ini 循环中选中 3 个复选框。我没有收到任何错误,但它不限制选择的数量。jQuery

$(document).ready(function() {
$('.single-checkbox').on('change', function() {
var noChecked = 0;
$.each($('.single-checkbox'), function() {
if ($(this).is(':checked')) {
noChecked++;
}
});
if (noChecked >= 3) {
$.each($('.single-checkbox'), function() {
if ($(this).not(':checked').length == 1) {
$(this).attr('disabled', 'disabled');
}
});
} else {
$('.single-checkbox').removeAttr('disabled');
};
});
});

php:

$query="SELECT course.name FROM course";
$results=mysqli_query($dbhandle,$query) or die(mysqli_error($dbhandle));
while ($rows=mysqli_fetch_assoc($results)) {

print("<td><input class='single-checkbox' type='checkbox' id='ch' /></d> <td>".$rows['name']."</td>");

一切正常,但限制不起作用。预先感谢您。

最佳答案

只需检查选中框的数量;如果太高,请勿选中该框!

$(".single-input").on("change", function() {
if (this.checked && $(".single-input:checked").length > 3) {
this.checked=false;
return false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" class="single-input" /><br/>
<input type="checkbox" class="single-input" /><br/>
<input type="checkbox" class="single-input" /><br/>
<input type="checkbox" class="single-input" /><br/>
<input type="checkbox" class="single-input" /><br/>
<input type="checkbox" class="single-input" /><br/>

关于jquery checkoxes 和 php 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52959091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com