1.我想在用户在选择框中选择一个值时启用自动完成,在用户取消选择时禁用
$("#selectorText").autocomplete({
source: function (request, response) {
$.getJSON("URL", {
term: $('#selectorText').val();/this the select box value
}, response);
},
minLength: 1,
select: function (event, ui) {
$(this).val(ui.item.value);
}
});
2.这是默认情况下在页面加载时禁用自动完成
$( "#selectorText" ).autocomplete({
disabled: true; //here is the code default disable
});
$('#selctBox').change(function () {
if(this.val()>0){
$( "#selectorText" ).autocomplete({
disabled: true
});
}
});
答案 0 :(得分:1)
你有解决方案。你的代码很好,只是稍微改变你的状态。
$(document).ready(function(){
//on page load
$( "#selectorText" ).autocomplete( "disable" );
// on selectbox change
$('#selctBox').change(function () {
if($(this).val() == 3 || $(this).val() == 4){
$( "#selectorText" ).autocomplete( "enable" );
} else {
$( "#selectorText" ).autocomplete( "disable" );
}
});
});
答案 1 :(得分:0)
$('#selctBox').change(function() {
var this_val = $(this).val();
if (3 <= this_val && this_val <= 4 ) {
$("#selectorText").autocomplete("option", "disabled", false);
}
else { // 1,2,5
$("#selectorText").autocomplete("option", "disabled", true);
}
});