简体   繁体   English

JQuery Searchable Dropdown框

[英]JQuery Searchable Dropdown box

I have a searchable list, created using JQuery Plugin from: http://plugins.jquery.com/searchit/ 我有一个可搜索的列表,使用JQuery插件创建: http//plugins.jquery.com/searchit/

But i want some value to be selected by default when the list box shows up first time. 但是我希望在列表框第一次显示时默认选择一些值。 Even though i have 'selected' mentioned in the option tag (Rockford in ex below). 即使我在选项标签中提到了“选择”(前面的罗克福德)。 This part is not working. 这部分不起作用。

Pls see here sample here: 请看这里的样本:

http://jsfiddle.net/QuYJD/22/ http://jsfiddle.net/QuYJD/22/

$("select").searchit( { textFieldClass: 'searchbox' } );

    Type the search text:
    <br/>
    <select id="listBox1">
      <option>Robinhood</option>
      <option selected >Rockford</option>
      <option>Rome</option>
      <option>Ronda</option>
      <option>Rondon</option>
      <option>Rondonopolis</option>
      <option>Rongelap</option>
    </select>

Any idea? 任何想法? Or any other solution... 或任何其他解决方案......

You can check the chosen plugin for jQuery. 您可以检查所选的jQuery 插件 Its more user friendly and has vary nice UI. 它更加用户友好,并具有不同的UI。

It has the feature which you are looking for. 它具有您正在寻找的功能。 Please go to the following link for more details 请转到以下链接了解更多详情

http://harvesthq.github.io/chosen/ http://harvesthq.github.io/chosen/

A kinda hacky way 有点hacky方式

Maybe you could do something like this after you init the plugin : 也许你在初始化插件后可以做这样的事情:

$(".searchbox").val($("#listBox1 :selected").val())

Because this plugin seems to be making you select into this: 因为这个插件似乎让你select这个:

<input type="textbox" id="__searchit2" class="searchbox">
<div id="__searchitWrapper2" style="display: none; vertical-align: top; overflow: hidden; border: 1px solid rgb(128, 128, 128); position: absolute;">
 <select id="listBox2" style="padding: 5px; margin: -5px -20px -5px -5px;">
  <option>Robinhood</option>
  <option>Rockford</option>
  <option selected="">Rome</option>
  <option>Ronda</option>
  <option>Rondon</option>
  <option>Rondonopolis</option>
  <option>Rongelap</option>
 </select>
</div>

Plugin change 插件更改

I added another option to the plugin called selected . 我在插件中添加了另一个名为selected If you set it to true , then the text box will show your selected option . 如果将其设置为true ,则文本框将显示您选择的option Just add this extra option : 只需添加以下额外选项:

$("select").searchit({
      textFieldClass: 'searchbox',
      selected: true
 });

Demo : http://jsfiddle.net/hungerpain/QuYJD/23/ 演示: http//jsfiddle.net/hungerpain/QuYJD/23/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM