除了一个复选框外,禁用所有选项 [英] Disable all but one checkbox
本文介绍了除了一个复选框外,禁用所有选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jsfiddle 上看到了这个问题,我想知道如何更改它如果且仅当检查45时,其余的都被禁用,如果45未被选择,则其余的被启用。
在jsfiddle上的示例javascript:
$(function(){
$(。rambo)。change(function(){
$(this).siblings()。attr ,$(this).is(:checked));
});
});
解决方案
/ code> s并选择
HTML:
< input type =checkboxid =cb1class =rambovalue ='1'/> 45
< input type =checkboxid =cb2class =rambovalue ='2'/> 56
< input type =checkboxid =cb3class =rambovalue ='3'/> 56
JS:
<
$(function(){
$(#cb1)。change(function(){
$(this).siblings()。attr(disabled,$ (this).is(:checked));
});
});
I saw this on jsfiddle and I wanted to know how I would alter it so that if and only if 45 is checked the rest are disabled, if if 45 is unselected then the rest are enabled. I should be able to do all this with out submitting the form.
The example javascript on jsfiddle:
$(function(){
$(".rambo").change(function(){
$(this).siblings().attr("disabled", $(this).is(":checked"));
});
});
解决方案
Just add proper id
s and select on that
HTML:
<input type="checkbox" id="cb1" class="rambo" value='1' /> 45
<input type="checkbox" id="cb2" class="rambo" value='2' /> 56
<input type="checkbox" id="cb3" class="rambo" value='3' /> 56
JS:
$(function(){
$("#cb1").change(function(){
$(this).siblings().attr("disabled", $(this).is(":checked"));
});
});
这篇关于除了一个复选框外,禁用所有选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文