最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Narrow down the select options from Text search using jQuery - Stack Overflow

programmeradmin1浏览0评论

I have some options in a select tag and a input text box. Once user enters something in text box the related options should be displayed rest needs to be hidden.

    <select size="8" style="width:150;">  
    <option value="something1">Apple</option>  
    <option value="something1">Banana</option>  
    <option value="something2">Mango</option> 
    <option value="something2">Orange</option> 
    <option value="something2">Papaya</option> 
    <option value="something3">Grape</option> 
    <option value="something3">Coco</option> 
    <option value="something3">Chocolate</option> 
 </select>
    <input type="text" > 

When I enter ap in text box, only Apple, Papaya should be visible.. Please let me know how I can achieve this by jQuery..

I have some options in a select tag and a input text box. Once user enters something in text box the related options should be displayed rest needs to be hidden.

    <select size="8" style="width:150;">  
    <option value="something1">Apple</option>  
    <option value="something1">Banana</option>  
    <option value="something2">Mango</option> 
    <option value="something2">Orange</option> 
    <option value="something2">Papaya</option> 
    <option value="something3">Grape</option> 
    <option value="something3">Coco</option> 
    <option value="something3">Chocolate</option> 
 </select>
    <input type="text" > 

When I enter ap in text box, only Apple, Papaya should be visible.. Please let me know how I can achieve this by jQuery..

Share Improve this question edited Aug 10, 2011 at 9:59 Vikram P asked Aug 10, 2011 at 9:31 Vikram PVikram P 852 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

demo: https://so.lucafilosofi./narrow-down-the-select-options-from-text-search-using-jquery

        $(function() {
               $('input.search').on('change', function() {
                    $(this).prev('select.term').find('option:not(:containsi(' + this.value + '))').hide();
                }).on('keyup', function() {
                    $(this).prev('select.term').find('option:containsi(' + this.value + ')').show().attr('selected', true);
                }).extend($.expr[':'], {
                'containsi' : function(elem, i, match, array) {
                    return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || '').toLowerCase()) >= 0;
                }
            });
        });

i suggest you to search and look at this SO post:

Jquery: Filter dropdown list as you type

or this example URL

http://andrew.hedges.name/experiments/narrowing/

发布评论

评论列表(0)

  1. 暂无评论