Ich möchte das Eingabefeld automatisch ausfüllen, wenn der Benutzer den richtigen Wert eingibt und das Eingabefeld ausblendet. Ein Beispiel dafür ist https://www.redbus.in/ Ich benutze URL-String, um Datenanforderung zu senden, und danach das Ergebnis erhalten. Ich möchte weiterhin die Datenanforderung senden und Ergebnisse erhalten, selbst wenn der Benutzer das Feld entdeckt? Dann muss der erste Wert der Liste mit Ergebnissen ausgewählt werden. DANKE FÜR DIE HILFE!jQuery Autocomplete mit Focusout-Lösung
Mein Code ist:
jQuery(document).ready(function(){
jQuery("#econt_offices_town").autocomplete({
minLength: 2,
autoFocus: true,
source: function(request, response) {
jQuery.ajax({
url: ajaxurl,
dataType: "json",
data: {
action:'handle_ajax',
city: request.term
},
success: function(data) {
response(jQuery.map(data, function(item) {
return {
label: item.label,
value: item.value,
city_id: item.id,
post_code: item.post_code
};
}));
}, //end of success
}); //end of ajax
}, //end of source
select: function(event, ui) {
var city_id = ui.item.city_id;
var post_code = ui.item.post_code;
jQuery('#econt_offices_postcode').val(post_code);
jQuery('#office_locator').show(); //show office locator button after the city is selected
jQuery('#econt_offices_postcode, label[for="econt_offices_postcode"], #econt_offices, label[for="econt_offices"]').show();
jQuery.ajax({
url: ajaxurl,
dataType: "json",
data: {
action:'handle_ajax',
office_city_id: city_id,
delivery_type: 'to_office'
},
success: function(data) {
jQuery('#econt_offices').empty()
jQuery.each(data, function(key, value) {
jQuery('#econt_offices').append(jQuery("<option/>", {
value: value.id,
text: value.value + ' [о.к.:' + value.id + ']'
}));
});
calculate_loading(); //calculate loading cost for shipping to office
} //end of success
}); //end of ajax
}, //end of select
}); //end of #econt_offices_town .autocomplete
nur eine Randnotiz, aber das sieht aus wie ein gutes Beispiel für eine Klasse: 'jQuery ('# econt_offices_postcode, Label [for = "econt_offices_postcode"], # econt_offices, label [für = "econt_offices"] '). show(); 'wie' jQuery ('. postcodethings '). show(); ' –