【问题标题】:Hooking event handlers to jQuery Autocomplete Combobox将事件处理程序挂钩到 jQuery 自动完成组合框
【发布时间】:2011-04-11 23:09:36
【问题描述】:

我想要一些关于如何为 jQuery 自动完成组合框设置事件处理程序的建议:http://jqueryui.com/demos/autocomplete/#combobox

jQuery 文档中的代码示例如下:

// Supply a callback function to handle the select event as an init option.
$( ".selector" ).autocomplete({
   select: function(event, ui) { ... }
});
// Bind to the select event by type: autocompleteselect.
$( ".selector" ).bind( "autocompleteselect", function(event, ui) {
  ...
});

我已经尝试过 - 如下所述 - 但它不起作用。我从这个已关闭的错误报告 (dev.jqueryui.com/ticket/5891) 中了解到我正在“实例化一个组合框,然后尝试使用自动完成设置选项”,但我不明白如何修复它。

// Have: <select id="comboInput" name="comboInput"> ....
$(document).ready(function() {
   $("#comboInput").combobox();
   $("#comboInput").autocomplete({
      select: function(event, ui) {
         alert("Value selected.");
      }
   });
});

谁能告诉我如何使这项工作?感谢您的帮助!

【问题讨论】:

    标签: jquery combobox autocomplete


    【解决方案1】:

    简而言之,这是为“选择”事件创建一个带有事件处理程序的组合框所需要的(应该是“选择”,但组合框只是一个原型):

    <script language="javascript" type="text/javascript">
       $(document).ready(function() {
          // For some SELECT with ID combobox
          $("#combobox").combobox({
             selected: function(event, ui) {
                // Event handling code goes here.
             } // selected
          }); // combo
       }); // ready
    </script>
    

    更多细节和讨论,请看我的博文:Event Handling with the jQuery Autocomplete Combobox

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    相关资源
    最近更新 更多