必须在选中“所有课程”时启用和禁用我的下拉列表。多选下拉确认

时间:2016-11-10 09:34:33

标签: asp.net-mvc validation checkbox

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。当我检查“所有课程”时它工作正常,我的texarea更新为“所有课程“但如果我取消选中它不工作。

1 个答案:

答案 0 :(得分: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);