有两个文本字段(具有自动完成功能):
<label for="name">Customer:</label>
<input type="text" name="customer" id="customer" value="" />
<input type="hidden" id="customer-id" />
<p id="customer-description"></p>
<label for="name">Store:</label>
<input type="text" name="store" id="store" value="" disabled="true" />
<input type="hidden" id="store-id" />
<p id="store-description"></p>如您所见,最初我禁用了第二个textfield。我想要的是当用户完成从customer中选择项目时,应该启用商店textbox。这是我尝试过的,但它没有启用存储字段:
$(function() {
$('#customer').autocomplete({
source: "./SearchCustomer.php?term="+document.getElementById("customer").value,
minLength: 0,
focus: function( event, ui ) {
$( "#customer" ).val( ui.item.label );
return false;
},
select: function (event, ui) {
$( "#customer" ).val( ui.item.label );
$( "#customer-id" ).val( ui.item.value );
return false;
}
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li>" ).append( "<a>" + item.label + "</a>" ).appendTo( ul );
};
$("#store").removeAttr("disabled").focus();
});你的帮助将不胜感激。
发布于 2013-08-05 09:29:39
尝尝这个
$(function() {
$('#customer').autocomplete({
source: "./SearchCustomer.php?term="+document.getElementById("customer").value,
minLength: 0,
focus: function( event, ui ) {
$( "#customer" ).val( ui.item.label );
return false;
},
select: function (event, ui) {
$( "#customer" ).val( ui.item.label );
$( "#customer-id" ).val( ui.item.value );
$("#store").removeAttr("disabled").focus();
return false;
}
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li>" ).append( "<a>" + item.label + "</a>" ).appendTo( ul );
};
});发布于 2013-08-05 09:30:40
将$('#store').prop('disabled', false).focus();添加到选择函数中:
select: function(ev, ui) {
$( "#customer" ).val( ui.item.label );
$( "#customer-id" ).val( ui.item.value );
$( "#store" ).prop( 'disabled', false ).focus();
return false;
}因此,当选择一个自动完成项时,将#store的禁用属性设置为false,并给出元素焦点。
这里有把小提琴
https://stackoverflow.com/questions/18054618
复制相似问题