0
我有自动完成我的网站上的工作有以下:jQuery UI的.autocomplete()
$(function() {
$("#client").autocomplete({
source: "/appointments/clients.json",
minLength: 1,
select: function (event, ui) {
$('input[name="clientid"]').val(ui.item.id);
$('#app-submit').html('Add Appointment for ' + ui.item.value);
}
});
});
我想现在要做的是,当未在下拉列表中显示的东西用户类型,我倒是像以下发生:
$('input[name="clientid"]').val('');
$('#app-submit').html('Add Appointment');
我使用下面的尝试,但没有奏效:
$(function() {
$("#client").autocomplete({
source: "/appointments/clients.json",
minLength: 1,
select: function (event, ui) {
if(typeof(ui.item)){
$('input[name="clientid"]').val(ui.item.id);
$('#app-submit').html('Add Appointment for ' + ui.item.value);
} else {
$('input[name="clientid"]').val('');
$('#app-submit').html('Add Appointment');
}
}
});
});