繁体   English   中英

我可以覆盖jQueryUI自动完成功能中的选择选项吗

[英]Can I overwrite select options in jQueryUI autocomplete

小提琴的例子

我的主要js文件中有一个自动完成代码。 这是一个例子:

var availableTags = [
    "ActionScript",
    "AppleScript",
    "Asp"
    ];
$("#tags").autocomplete({
    source: availableTags,
    select: function(event, ui) {
      return false; 
    }
});

我有一个单独的js文件,该文件仅在特定页面上提供。 在该文件中,我想覆盖$("#tags")实例中的select选项,这是该单独的js文件中的示例:

$.widget( "ui.autocomplete", $.ui.autocomplete, {
   select: function (event, ui) {
     $(this).val(ui.item.label);  // to automatically populate the input box with the selected option  
  }
});

是否有可能像jQuery中那样覆盖选择选项?

使用option方法。 所有jQuery小部件都有一个option方法 ,该方法允许您更改选项。 而且所有jQuery小部件方法都被称为$().widgetname("method",arg1,arg2,...)

http://jsfiddle.net/b9awbcuf/

$("#tags").autocomplete("option", "select", function (event, ui) {
    alert('changed');
    $(this).val(ui.item.label);
});

这是非常有用的内容: http : //learn.jquery.com/jquery-ui/how-jquery-ui-works/

暂无
暂无

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

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