我进行了实时 ajax 搜索,并尝试将结果分为 2 个类别,这是可行的。我遇到的问题是,当我输入或删除一个字符时,列表结果会增加相同的项目而不是定义。结果的数量也以一种非常奇怪的方式显示。
$("#searchterm").keyup(function (e) {
var q = $("#searchterm").val();
$.getJSON('https://www.googleapis.com/books/v1/volumes?q=:isbn=0-13-727827-6',
function (data) {
$("#results").empty();
$("#results").append("Results for <b>" + q + "</b>");
$.each(data.items, function (i, item) {
var title = item.volumeInfo.title;
$.each(item.volumeInfo.industryIdentifiers, function (i2, type) {
$("<div/>")
.append(title)
.appendTo("div[id='" + type.type + "']");
$(".number").append(" total " + type.type.length);
});
});
});
});
请查看小提琴http://jsfiddle.net/sFn8t/并随时对其进行修改,以便其他人可以将其用作示例。提前致谢。