此搜索功能在Mozilla中运行良好,但在Chrome中无效。
如果我第一次输入搜索关键字,则不会在html-markup中处理Json字符串。第二次它确实有效。
$("#srch").autocomplete({
delay: 0,
minLength: 4,
appendTo: "#tbar",
open: function() {
var position = $("#tbar").position(),
left = position.left, top = position.top;
$("#tbar > ul").css({left: left + 0 + "px",top: top + 23 + "px" });
$('ul.ui-autocomplete').addClass('opened')
.css('display','block');
},
close: function () {
$('ul.ui-autocomplete')
.delay(1500)
.removeClass('opened')
},
source: function (a, b) {
$.getJSON("/v4/ajax/search.php?q=" + a.term + "&format=json", function (a) {
b(a)
})
},
select: function (a, b) {
$("#srch").val(b.item.resort_name);
},
focus: function (a, b) {
$("#srch").val(b.item.resort_name);
}
}).data("ui-autocomplete")._renderItem = function (a, b) {
return $("<li></li>")
.data("item.autocomplete", b)
.append('<em class="nat nat-' + b.sym + '"></em> <span><a href="/webcams/' + b.resort_us + '">' + b.resort_name + '</a></span> ')
.append('<span><a href="/webcams/' + b.canton_us + '">' + b.canton + '</a></span> <small>' + b.cnt + ' cams</small> ')
.appendTo(a)
}