2013-12-08 47 views
0

我已經使用上面的代碼工作,感謝這裏的幫助。但是,我想對其進行修改,以便當用戶從月份開始菜單中選擇「十二月」時,將顯示「十二月」禁用月末菜單。基於其他輸入啓用和禁用菜單

此外,如果用戶返回並從月份開始菜單中選擇不同的月份,我想再次啓用月份結束菜單。

我一直在嘗試各種if語句,但我似乎無法得到它與我公認的有限的技能工作。

謝謝!

JSFiddle here.

$("select[name='monthSelect']").attr('disabled', 'disabled'); 

$("select[name='catFrequency']").change(function() { 
    var jSelect1=$("select[name='monthSelect']"); 

    if(jSelect1.attr('disabled')) { 
     jSelect1.removeAttr('disabled'); 
     $('#recurBegin').find("option[value='']").remove(); 
     $('#recurEnd').find("option[value='']").remove(); 
     $('#recurEnd').find("option[value='12']").prop('selected', true); 
    } 
    else 
    { 
     jSelect1.attr('disabled', 'disabled'); 
     $("#recurBegin").prepend("<option value='' selected='selected'></option>"); 
     $("#recurEnd").prepend("<option value='' selected='selected'></option>"); 
    } 
}); 
    var end = $('#recurEnd'); 
    $('#recurBegin').change(function() { 
    var index = $(this).find('option:selected').index(); 
    end.find('option').show(); 
    end.find('option:lt(' + (index + 1) + ')').hide(); 
}); 
}); 

回答

1

fiddle Demo

var end = $('#recurEnd'); 
$('#recurBegin').change(function() { 
    if (this.value == 12) {//if month selected is December 
     end.val(12);// set End month to December 
     end.prop('disabled', true);//disable month end 
    } else { 
     var index = $(this).find('option:selected').index(); 
     end.prop('disabled', false);//enable month end 
     end.find('option').show(); 
     end.find('option:lt(' + (index + 1) + ')').hide(); 
     end.find('option:eq(' + ++index + ')').prop('selected', true); 
    } 
}); 

.prop()

+1

哈哈......再次感謝圖莎爾!那很棒。 – hyphen

+0

@ user1476992歡迎高興幫忙:) –