我在 Wordpress 插件中使用 jQuery Autocomplete。失焦时如何取消 ajax/自动完成?
$first_id
由 PHP 传递并允许多个实例。
jQuery(document).ready(function ($){
$("#'.$first_id.'").autocomplete({
source: function(req, add){
$.getJSON("'.site_url().'/wp-admin/admin.php?page=church_admin/index.php&action=get_people&callback=?", req, function(data) {
//create array for response objects
var suggestions = [];
//process response
$.each(data, function(i, val){
suggestions.push(val.name);
});
//pass array to callback
add(suggestions);
});
},
select: function (event, ui) {
var terms = $("#'.$first_id.'").val().split(", ");
// remove the current input
terms.pop();
console.log(terms);
// add the selected item
terms.push(ui.item.value);
console.log(terms);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
$("#'.$first_id.'").val(this.value);
return false;
},
minLength: 3,
});
});