Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter-将复选框限制为9个选项,禁用其余选项并发布到新页面?_Codeigniter_Post_Checkbox_Limit - Fatal编程技术网

Codeigniter-将复选框限制为9个选项,禁用其余选项并发布到新页面?

Codeigniter-将复选框限制为9个选项,禁用其余选项并发布到新页面?,codeigniter,post,checkbox,limit,Codeigniter,Post,Checkbox,Limit,我正在寻找一个基于Codeigniter的解决方案,在这个解决方案中,我可以从MySQL表中加载一个页面,其中的复选框包含身份证背面的背书。我已经能够加载带有5列10行复选框的页面,这很好 我不能做的是将选择限制在50个选项中的9个,并将复选框值发布到另一个页面 如果使用jquery通过以下语句禁用其余未选中框: $inputs.not(this).prop('disabled',true);“ 它将只发布最后选择的选项。另一方面,如果我没有禁用复选框或在限制之前提交,那么帖子可以在下一页的数组

我正在寻找一个基于Codeigniter的解决方案,在这个解决方案中,我可以从MySQL表中加载一个页面,其中的复选框包含身份证背面的背书。我已经能够加载带有5列10行复选框的页面,这很好

我不能做的是将选择限制在50个选项中的9个,并将复选框值发布到另一个页面

如果使用jquery通过以下语句禁用其余未选中框:

$inputs.not(this).prop('disabled',true);“

它将只发布最后选择的选项。另一方面,如果我没有禁用复选框或在限制之前提交,那么帖子可以在下一页的数组中正常工作,其中包含我选择的背书。我在Codeigniter中尝试了很多方法来实现这一点,并寻找解决方案,但都没有成功。如果有人能帮我,我将不胜感激。我正在接近完成这个项目,已经为此奋斗了一段时间

下面是我在网上找到的我正在使用的脚本:

<script>
$(document).ready(function () {
$('input:checkbox').click(function(){
var $inputs = $('input:checkbox')
if($(":checkbox").filter(':checked').length==9){
$inputs.not(this).prop('disabled',true); 
}else{
$inputs.prop('disabled',false);
}
})
})
</script>

$(文档).ready(函数(){
$('input:checkbox')。单击(函数(){
变量$inputs=$('input:checkbox')
if($(“:checkbox”).filter(“:checked”).length==9{
$inputs.not(this.prop('disabled',true));
}否则{
$inputs.prop('disabled',false);
}
})
})

您可以像选中任何复选框一样添加选中的类别,当限制达到9时,禁用所有复选框,然后从选中类别的复选框中删除禁用属性

<script>
$(document).ready(function () {
$('input:checkbox').click(function(){
$(this).addClass("checked");
var $inputs = $('input:checkbox')
if($(":checkbox").filter(':checked').length==9){
$("input[type=checkbox]").prop('disabled',true); 
$(".checked").removeAttr("disabled");

// submit the form 
}else{
$inputs.prop('disabled',false);
}
})
})
</script>

$(文档).ready(函数(){
$('input:checkbox')。单击(函数(){
$(此).addClass(“选中”);
变量$inputs=$('input:checkbox')
if($(“:checkbox”).filter(“:checked”).length==9{
$(“输入[类型=复选框]”).prop('disabled',true);
$(“.checked”).removeAttr(“禁用”);
//提交表格
}否则{
$inputs.prop('disabled',false);
}
})
})

dianuj,谢谢您的回复。我确实尝试了您回复的代码,我得到了一个“ReferenceError:输入未定义”。当我去打第10次代言时,它就出现了。有什么想法吗?dianuj,我能够找到哪里出了问题,我必须在下面的行中输入:$(输入[type=checkbox]).prop('disabled',true);到$('input[type=checkbox]')。prop('disabled',true);再次感谢您提供的解决方案。我真的很感激。:)@克里斯法伦:对不起,我很匆忙,没有意识到我错过了引语:)