[英]JQueryUI autocomplete doesn't update its data-attribute from the select box
$('select').change(function(){
$('#auto').attr('data-id',$(this).val())
})
$('#auto').autocomplete({
delay: 1000,
source: function( request, response ) {
alert($(this.element).data('id'))
return false
}
})
<select name="category">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<input id="auto" data-id="A" type="search"/>
I want to update the auto-input data attribute when someone select an option in the selectbox. 当有人在选择框中选择一个选项时,我想更新自动输入数据属性。
Is there any way to prevent the auto-complete input from caching its data attribute? 有什么方法可以防止自动完成输入缓存其数据属性? The input is able to update the data-id
the first time I change the option from A to B in the selectbox. 第一次将选择框中的选项从A更改为B时,输入即可更新data-id
。 But when I change from B
to C
, the input is still alerting B
instead of C
. 但是,当我从B
更改为C
,输入仍在提醒B
而不是C
Is $(this.element).data('id')
not an appropriate way of getting the latest data attribute? $(this.element).data('id')
不是获取最新数据属性的适当方法?
what about picking the value directly from the select control, like this: 直接从select控件中选择值怎么样?
$('#auto').autocomplete({
delay: 100,
source: function( request, response ) {
var selected = $('select[name="category"] option:selected'),
isSomethingSelected = selected.length == 1,
selectedVal = isSomethingSelected ?
selected.val() :
$('select[name="category"] option:first').val();
alert(selectedVal);
return false;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.