日期:2014-05-16  浏览次数:20358 次

可输入下拉框 自动匹配【editable select】
有谁用过editable select 的

官网demo: http://coffeescripter.com/code/editable-select/

现在问题是  text文本我也想取、 option 里的value 也想取、这俩值分别如何取到?

是不是需要修改js源码 、

<select name="drpPublisher" id="drpPublisher" >
    <option value="0">--请选择--</option>
            <option value="1">第一个</option>
            <option value="2">第二个</option>
</select>


$(function() {
  $('#drpPublisher').editableSelect(
    {
      bg_iframe: false,
      onSelect: function(list_item) {
        // 'this' is a reference to the instance of EditableSelect
        // object, so you have full access to everything there
        //alert('List item text: '+ list_item.val());
        //$('#ddd').val(this.text.val());
 alert('List item text: '+ list_item.text());
        // 'this' is a reference to the instance of EditableSelect
        // object, so you have full access to everything there
        alert('Input value: '+ this.text.val());//取不到option 的value
      },
      case_sensitive: true, // If set to true, the user has to type in an exact
                             // match for the item to get highlighted
      items_then_scroll: 10 // If there are more than 10 items, display a scrollbar
    }
  );
});



想要的结果:

当我尝试输入  “第”的时候   匹配出来 第一个  第二个   然后我选择第一个的时候  弹出 1 和第一个 就可以、


------解决方案--------------------
      onSelect: function(list_item) {
        alert('List item text: '+ list_item.val());
        alert('Input value: '+ list_item.text());
      },
有这个不用?
------解决方案--------------------
$("#drpPublisher").val();取到value里面的值;

$("#drpPublisher").text();取到text里面的值;

------解决方案--------------------
你要修改源代码了。。这个模拟的,div+ul+css,li里面显示的就是option的value【如果没有value显示option的text】
------解决方案--------------------

xue xi le