如果选中某个特定项目,则禁用所有复选框列表项目
Disable all the checkboxlist items if one of the particular item is selected
我有一个复选框列表。它有三个项目
- 雄性2.女性3.未知
如果有人选择了"未知",那么它应该禁用复选框列表上的其他选择。如果选择了"未知",则无法选择任何内容。任何j查询、java脚本、c代码都有帮助,请。。。
您可以尝试以下操作:-
$('.optionBox input:checkbox').click(function(){
var $x= $('.optionBox input:checkbox');
if($(this).is(':checked')){
$x.not(this).prop('disabled',true);
}
else
{
.....
}
})
您可以在jquery中使用以下代码来处理此问题。
$(document).ready(function(){
$("#unknown").change(function(){
if($(this).is(":checked"))
$("#male, #female").attr('disabled','disabled');
else
$("#male, #female").removeAttr('disabled','disabled');
});
});
这是演示http://jsfiddle.net/nKdJg/3/
在这里,试试这个:http://jsfiddle.net/m8Leu/
// store the inputs and bind the change event
var $inputs = $( ".chkGroup input" );
$inputs.on( "change" , function(e) {
// store the item that changed and the ones that didnt.
var $changed = $(e.target);
var $others = $inputs.not( $changed );
// if the item that changed is "unknown"
if( $changed.hasClass( "unique" ) ) {
// save the state of the "unknown" chk
// and set the other chks to it's state
var state = $changed.prop( "checked" )
$others.prop( "disabled", state );
// for good measure, we'll uncheck the
// others because they are disabled
if( state ) {
$others.prop( "checked" , false );
}
}
});
相关文章:
- 角度的项目列表 ng 重复,ng 单击显示全宽描述
- 当在Ember中点击一个项目时,我如何将一个活动类添加到项目列表中
- 在javascript中搜索项目列表的性能
- 如何在角度js的自动完成下拉列表中对项目列表(按字母顺序)进行排序
- 从项目列表Jquery中仅选择(显示:块)元素
- 使用 JQuery 复选框筛选项目列表
- 如何在Javascript中设置随机生成的项目列表的样式
- 如何无限循环项目列表
- 将项目列表馈送到3列布局中
- Polymer 1.0:管理简单项目列表的最佳实践
- 从select创建项目列表/数组
- 渲染Backbone.js中项目列表中的项目
- 如何将特定项目信息链接到 emberjs 中项目列表中的模板
- 如何遍历项目列表并将其数据值推送到数组中
- NodeJS:如何使用异步.js来处理数据库中的项目列表
- 挖空 JS 构建项目列表
- 通过指定的文本检查项目列表 /w Jquery
- 如何制作一个项目列表,可以使用 Angular JS 单独切换
- 将单词“and”放在项目列表的文本中
- 优化显示简单项目列表的模型/视图