比较两个jquery ui自动完成组合框值? [英] Comparing two jquery ui autocomplete combobox values?
问题描述
如何比较两个jquery ui自动完成组合框值,而不是jquery生成的输入值,但< select>< option value =foo>< / option>< /选择>
值?如何获取这些值并在每次更改时比较它们中的任何一个?
How to compare two jquery ui autocomplete combobox values, not input values that are generated by jquery but <select><option value="foo"></option></select>
values? How to get this values and compare them, everytime they are changed, either one of them?
推荐答案
我第一次没有正确理解你的问题。
I did not reallt understand your question correctly the first time.
我想你从 jQuery UI自动完成演示页?
如果查看代码,它会在选择发生时触发选中事件:
If you look at the code, it triggers an event "selected" when a selection happens:
select: function(event, ui) {
ui.item.option.selected = true;
// triggers the "selected" event
self._trigger("selected", event, {
item: ui.item.option
});
},
由于组合框示例使用jQuery UI Widget Factory,您可以轻松绑定初始化插件实例时,来自选项的此事件的事件处理程序:
As the combobox example uses the jQuery UI Widget Factory, you can easily bind an event handler for this event from the options when initializing the plugin instance:
$( "#combobox" ).combobox({
selected: function(e, ui) {
// in here "ui.item" is the <option> selected
// so you can use "ui.item.value"
}
});
这将作为一种变更处理程序。在其中,您可以通过 ui.item.value
访问值。
$
有关的工作示例jsfiddle 。
This will act as sort-of "change handler". In it, you have access to the value through ui.item.value
.
Working example on jsfiddle.
这篇关于比较两个jquery ui自动完成组合框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!