JQuery UI - 如何将更改事件绑定到组合框?
所以问题是自动完成组合框是在没有更改事件的情况下初始化的。我想稍后绑定它,但文档似乎对组合框不够充分。
不起作用的代码:
$('#select').combobox();
...
$('#select').bind( "autocompletechange", function(event, ui) {
alert('changed');
});
我猜测事件标签是错误的,因为组合框上的内联标签被“选中”,例如 $('#select').combobox({selected : function(ev,ui) { alert('selected'); }});
有效,但我不能那样使用它。
那么你知道该事件的正确标签是什么吗?我只是在文档中找不到它。
编辑:实际上我找到了我的问题所在。 $('#select').combobox();
只是将选择映射到自动完成输入。它创建的输入具有类似于 id='select-autocomplete'
的 id,因此要将事件绑定到该组合框 - 选择器应该位于此输入上,而不是选择上。所以工作代码:
$('#select').combobox();
...
$('#select-autocomplete').bind( "autocompletechange", function(event, ui) {
alert('changed');
});
So the problem is the autocomplete combobox is initialized without the change event. I want to bind it afterwards but the documentation seems to be inadequate about the combobox.
Code that doesn't work:
$('#select').combobox();
...
$('#select').bind( "autocompletechange", function(event, ui) {
alert('changed');
});
I am guessing the event label is wrong since the inline label on the combobox is "selected" e.g. $('#select').combobox({selected : function(ev,ui) { alert('selected'); }});
works but I can't use it that way.
So any idea what's the correct label of the event? I just can't find it in the documentation.
EDIT: Actually I found where my problem was. $('#select').combobox();
just maps a select to an autocomplete input. The input it creates has an id like id='select-autocomplete'
, so to bind and event to that combobox - the selector should be on this input instead on the select. So the working code:
$('#select').combobox();
...
$('#select-autocomplete').bind( "autocompletechange", function(event, ui) {
alert('changed');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我找到了比将事件绑定到创建的 .ui-combobox-input 更清晰的解决方案。您应该在组合框代码中找到初始化输入的位置,并找到选择参数。
修改这部分代码:
So, I found more clear solution than binding event to created .ui-combobox-input. You should find in combobox code place where input is initialized, and find select parameter.
Make changes in this part of code: