【发布时间】:2013-08-11 12:11:37
【问题描述】:
我有一个复选框列表。其中包含三个项目
- 男 2.女性 3.未知
如果有人选择了未知,那么它应该禁用复选框列表上的其他选择。如果选择了未知,则无法选择任何内容。 任何 j 查询、java-script、c# 代码都请帮忙...
【问题讨论】:
标签: javascript jquery checkbox checkboxlist
我有一个复选框列表。其中包含三个项目
如果有人选择了未知,那么它应该禁用复选框列表上的其他选择。如果选择了未知,则无法选择任何内容。 任何 j 查询、java-script、c# 代码都请帮忙...
【问题讨论】:
标签: javascript jquery checkbox checkboxlist
你可以试试这样的:-
$('.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/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 );
}
}
});
【讨论】: