how to display default(static) text to jquery autocomplete dropdown

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-04 06:33:13

问题


I have a jquery autocomplete and it works just fine. Now i want to add a default text in the dropdown like

Input box if the user types.. ja

It should display below

Select below category [should be there all the time]

java

javascript

Any suggestion on how to do it..

  // Ajax Auto suggestion box

    var options, a;
    jQuery(function()
    {

    a = $('#txtOccupation').autocomplete({
      serviceUrl: '/App_Handlers/GetAjaxSuggestions.ashx?datasets=occ',
      minChars: 1,
      delimiter: /(,|;)\s*/,
      deferRequestBy: 0, //miliseconds
      noCache: false,
      width: 420,
      onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data);             },
     });



    browser = jQuery.browser;
    $('.autocomplete').css('padding-left','10px');
    });

HTML

**  <input type="text" class="placeholder-text" maxlength="100" value="Job title, Keyword or O*NET code" onfocus="if(this.value=='Job title, Keyword or O*NET code')this.value=''" onblur="if(this.value=='')this.value='Job title, Keyword or O*NET code'" id="txtOccupation" name="txtOccupations" autocomplete="off"></input>**

回答1:


I am providing answer to:

But its adding at the end, i want it to be on top. in your comment.

Based on the below your fiddle jsfiddle.net/J5rVP/158, I forked new fiddle http://jsfiddle.net/a3Tun/ to add element at top.

I have changed ui.content.push to ui.content.unshift.

unshift is like push, but it insert value at top of array. For more info, refer http://www.w3schools.com/jsref/jsref_unshift.asp



来源:https://stackoverflow.com/questions/23522253/how-to-display-defaultstatic-text-to-jquery-autocomplete-dropdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!