2
我是新手typeahead.js和工作自动完成与引导搜索框....我的jquery工作正常,当我想加载数据(option1,option2..etc)on的document.ready .....这里是下面的代码...Typeahead不工作与jquery keyUp函数
$(function() {
function displayResult(item) {
$('.alert').show().html('You selected <strong>' + item.value + '</strong>: <strong>' + item.text + '</strong>');
}
$(document).ready(function() {
$.ajax({
type: 'GET',
url:'QuickSearch?City='+"Bengaluru",
dataType: 'json',
success: function(data){
var j=jQuery.parseJSON(data.jsonAreaList);
var cool=j;
$('#demo1').typeahead({
source: j,
onSelect: displayResult
});
},
error: function(data)
{//When fails to load the Areas.
}
});
return false;
});
所有区域都得到正确加载....我现在的要求是我不想上document.onready负荷区.. ..喜欢从用户的查询和设置结果输入文本框.....这里是我正在尝试
$(function() {
function displayResult(item) {
$('.alert').show().html('You selected <strong>' + item.value + '</strong>: <strong>' + item.text + '</strong>');
}
$(document).ready(function() {
$("#SearchBox").keyup(function() {
var city=$("#SearchBox").val();
$.ajax({
type: 'GET',
url:'QuickSearch?City='+city,
dataType: 'json',
success: function(data){
var j=jQuery.parseJSON(data.jsonAreaList);
var cool=j;
$('#demo1').typeahead({
source: j,
onSelect: displayResult
});
},
error: function(data)
{//When fails to load the Areas.
}
});
return false;
});
});
});
我不getti ng在哪里我做错了...... :(
嘿@noob在第二个例子中我得到的结果列表(JSON)...市是第二个例子动态.... :)还有一个件事绑定功能没有效果... :( – 2015-02-11 13:14:09
我知道,但你能看到拼写错误'城市'的'城市'?? – 2015-02-11 13:17:03
哦对不起noob这是一个typop错误... :) – 2015-02-12 03:57:58