如何在点击一个复选框时禁用其他复选框?
我该怎么做?如何在点击一个复选框时禁用其他复选框?
- 如果点击
Replacement of Registration
,禁用Honorable Dismissal
和Entrance Exam
- 如果
Good Moral Certificate
被点击时,禁用Entrace Exam
- 如果
Honorable Dismissal
,禁用Diploma
,CUE Request
,CMI Request
,Entrance Exam
- 如果点击
Transcript of Record
,禁用CUE Request
,CMI Request
,Entrance Exam
- 如果
Entrance Exam
,禁用所有
<input type="checkbox" name="ac_description[]" value="Replacement_of_Registration">
<input type="checkbox" name="ac_description[]" value="Good_Moral_Certificate">
<input type="checkbox" name="ac_description[]" value="Honorable_Dismissal " >
<input type="checkbox" name="ac_description[]" value="Transcript_of_Record">
<input type="checkbox" name="ac_description[]" value="Diploma">
<input type="checkbox" name="ac_description[]" value="CUE_Request">
<input type="checkbox" name="ac_description[]" value="CMI_Request">
<input type="checkbox" name="ac_description[]" value="Entrance_Exam">
<input type="checkbox" name="ac_description[]" value="School_fees-Medical/Dental_Laboratory">
<input type="checkbox" name="ac_description[]" value="School_fees-Transcript/Honorable">
<input type="checkbox" name="ac_description[]" value="School_fees-Library">
<input type="checkbox" name="ac_description[]" value="Affiliation_Fees">
你会在输入标签的结尾,例如把残疾:
<input type = "checkbox"name = "ac_description[]" value = "Good_Moral_Certificate" >
<input type = "checkbox" name = "ac_description[]" value = "Honorable_Dismissal " >
<input type = "checkbox" name = "ac_description[]" value = "Transcript_of_Record">
<input type = "checkbox" name = "ac_description[]" value = "Diploma" disabled>
第四复选框将被禁用。你可以使用jQuery来操纵它。 使用jQuery你可以让一个事件发生在复选框被触发时,它将禁用的属性应用到其他框。 看看这个答案:Disable/enable an input with jQuery?
如果你想禁用一个组,给每组输入分配一个类,然后使用jQuery来改变它们。看看这篇文章,以及:Catch checked change event of a checkbox
这里是你可能想尝试什么样的例子:
$('.class_name').each(function(){
$this.onClick(function(){
if($(this).is(':checked')){
$('.class_name').each(function(){
if($(this).not(':checked')){
$(this).prop('disabled', true);
}
})
}
}) });
如何制作一个jQuery和脚本?谢谢 –
您可能想为每个分组创建一个班级,您只能从中选择一个复选框。然后为每个类分配一个监听器。 – KingLagalot
拼凑此代码段从最新从你的问题的理解,
$("input[type='checkbox']").click(function(){
var val = $(this).attr('value');
switch(val) {
case 'Replacement_of_Registration':
if($(this).is(':checked'))
$("input[value='Honorable_Dismissal '], input[value='Entrance_Exam']").prop('disabled',true);
else
$("input[value='Honorable_Dismissal '], input[value='Entrance_Exam']").prop('disabled',false);
break;
case 'Good_Moral_Certificate':
if($(this).is(':checked'))
$("input[value='Entrance_Exam']").prop('disabled',true);
else
$("input[value='Entrance_Exam']").prop('disabled',false);
break;
case 'Honorable_Dismissal ':
if($(this).is(':checked'))
$("input[value='Diploma'], input[value='CUE_Request'], input[value='CMI_Request'], input[value='Entrance_Exam']").prop('disabled',true);
else
$("input[value='Diploma'], input[value='CUE_Request'], input[value='CMI_Request'], input[value='Entrance_Exam']").prop('disabled',false);
break;
case 'Transcript_of_Record':
if($(this).is(':checked'))
$("input[value='CUE_Request'], input[value='CMI_Request'], input[value='Entrance_Exam']").prop('disabled',true);
else
$("input[value='CUE_Request'], input[value='CMI_Request'], input[value='Entrance_Exam']").prop('disabled',false);
break;
case 'Entrance_Exam':
if($(this).is(':checked'))
$("input[name='ac_description[]']").not(this).prop('disabled',true);
else
$("input[name='ac_description[]']").not(this).prop('disabled',false);
break;
});
仍然没有运作。 –
什么不起作用,你可以更具体。 –
你们是不是要禁止所有每当一个盒子已被检查其他框或禁用一定的盒子? – spiritwalker
因此更改事件和逻辑 – epascarello
-if单击替换注册,禁用授予退出和入学考试 -if单击良好道德证书,禁用入学考试 - 如果授予退休,禁用文凭,CUE请求,CMI申请,入学考试 -if录制成绩单被点击,禁用CUE请求,CMI请求,入学考试 -if入学考试,全部停用 –