3

チェックボックスリストがあります。これには3つのアイテムがあります

  1. 男性 2.女性 3.不明

誰かが不明を選択した場合、チェックボックスリストの他の選択を無効にする必要があります。[不明] が選択されている場合は、何も選択できません。j クエリ、Java スクリプト、C# コードはすべて役に立ちます...

4

3 に答える 3

1

次のようなことを試すことができます:-

$('.optionBox input:checkbox').click(function(){
    var $x= $('.optionBox input:checkbox'); 
    if($(this).is(':checked')){ 
       $x.not(this).prop('disabled',true); 
    }
    else
    {
     .....
    }
})
于 2013-08-11T12:17:05.510 に答える
1

これを処理するには、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/ です

于 2013-08-11T12:27:07.353 に答える
0

ここで、これを試してください: 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 );
    }

  }

});
于 2013-08-11T12:37:32.037 に答える