0
我想篩選一些下拉選擇對方的對話框,但我得到一些奇怪的行爲與選項之一。篩選選擇下拉框選項
這是jQuery的我使用:
$(document).ready(function() {
$('select:gt(0)').find('option:gt(0)').hide().prop('disabled', true);
$('#C5R').change(function() {
$('select:gt(0)').find('option:gt(0)').hide();
var thisVal = $(this).val();
if (thisVal == 1) {
$('#C5T').find('option').each(function() {
var thisVal = $(this).val();
$(this).hide().prop('disabled', true);;
if ((thisVal >= 1) && (thisVal <= 11)) {
$(this).show().prop('disabled', false);;
}
});
} else if (thisVal == 2) {
$('#C5T').find('option').each(function() {
var thisVal = $(this).val();
$(this).hide().prop('disabled', true);;
if ((thisVal >= 12) && (thisVal <= 32)) {
$(this).show().prop('disabled', false);;
}
});
} else if (thisVal == 3) {
$('#C5T').find('option').each(function() {
var thisVal = $(this).val();
$(this).hide().prop('disabled', true);;
if ((thisVal >= 33) && (thisVal <= 51)) {
$(this).show().prop('disabled', false);;
}
});
}
});
});
理論上它工作正常,第二個下拉過濾第一個(我沒有到編程過濾在第三屆,所以請忽略它),但是當選擇Essex(第三選項)時,選項在第二個下拉菜單中不能正確顯示。實際下拉框無法正確呈現(在Chrome中,未在其他瀏覽器中測試過)。
有沒有人有解決方案/解決這個問題?
jsfiddle實際上對我來說很好(OSX上的Chrome)。你使用的是什麼版本的Chrome和操作系統? –
Chrome 31.0.1650.63 m和win 7 – user2121189
我剛剛意識到您正試圖隱藏選擇選項,據我所知這是不可能的(至少不是在Chrome中)。看到[這個問題](http://stackoverflow.com/questions/4398966/how-can-i-hide-select-options-with-javascript-cross-browser)瞭解更多信息 –