2016-11-10 50 views
0
function updateTextArea() 
{  
    var allVals = [];  
    $('#coursedropdown :checked').each(function() 
    { 
     if ($(this).val() == "All Courses") 
     { 

      if($(this).attr('checked')) 
      { 
       $("input[type=checkbox][name='course-dropdown-list']").attr('checked', true); 
       allVals.push($(this).val()); 
      } 
      else 
       if($(this).val() != "All Courses") 
       { 

       $("input[type=checkbox][name='course-dropdown-list']").attr('checked', false); 
       $(this).val() == ""; 
       allVals.push($(this).val());               
      } 
     }    
     else 
     {   
      allVals.push($(this).val()); 

     }   
    });  
    $('#course').val(allVals); 
} 

當我的「所有課程」選項被選中時,我必須檢查剩餘的所有選項在下拉列表中,反之亦然,我必須相應地更新我的textarea.when我檢查「所有課程」其工作正常和我的texarea更新爲「所有課程」,但如果我取消其不工作。必須在選中「所有課程」時啓用和禁用我的下拉列表。多選下拉驗證

回答

0

試試這個

$("#checkbox1").val("FALSE"); 
function onCheckChange() { 
if ($("#checkbox1").is(':checked')) { 
$("#dropdown1").attr('disabled', 'disabled'); 
$("#checkbox1").val("TRUE"); 
} else { 
$("#dropdown1").removeAttr('disabled'); 
} 
} 
$("#checkbox1").click(onCheckChange).change(onCheckChange);