2011-03-09 22 views

回答

2
var input = $('input'), 
    select = $('select'); 


input.keyup(function() { 
    var inputVal = $(this).val(), 
     inputLength = inputVal.length; 

    select.find('option').each(function() { 

     if ($(this).val().substr(0, inputLength) != inputVal) { 
      $(this).attr({ disabled: 'disabled' }); 
     } else { 
      $(this).removeAttr('disabled'); 
     } 

     select.focus(); 
     input.focus(); 

    }); 

}); 

jsFiddle

重点关注select,然后返回的是让浏览器重新绘制它在我的(Chrome 9)中没有做的更改。

如果您希望他们实际上被删除,您需要删除它们并根据需要重新添加它们,因为display: none不适用于我。