文本到jQuery的自动完成下拉菜单

文本到jQuery的自动完成下拉菜单

本文介绍了如何显示默认(静态)文本到jQuery的自动完成下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自动完成的jQuery,它工作得很好.现在,我想在下拉列表中添加一个默认文本,例如

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

如果用户输入.. ja

Input box if the user types.. ja

它应该显示在下面

选择以下类别[应该一直存在]

Select below category [should be there all the time]

java

javascript

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>**

推荐答案

我提供以下答案:

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

根据您的提琴 jsfiddle.net/J5rVP/158 的下面,我分叉了新的提琴 http://jsfiddle.net/a3Tun/在顶部添加元素.

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

我已将ui.content.push更改为ui.content.unshift.

unshift类似于push,但是它在数组顶部插入值.有关更多信息,请参考 http://www.w3schools.com/jsref/jsref_unshift.asp

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

这篇关于如何显示默认(静态)文本到jQuery的自动完成下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:16