我想使用bootstrap Typehead自动填充,但我感到困惑,我正在使用下面的JS,这可以帮助任何人在这方面。我的要求是:任何用户使用typehead填充的内容都应该进入文本区($myTextarea)。
我想要将选定的值放入文本区域。
$(document).ready(function() {
$('input.typeahead').typeahead({
source: function (query, process) {
$.ajax({
url: '/test/typehead/data.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + query,
success: function(data) {
console.log(data);
process(data);
}
});
}
});
updater: function(item) {
$myTextarea.append(item, ' ');
return '';
}
}); 谢谢,阿肖克
发布于 2013-09-19 16:56:20
Solved....Some语法错误
$(document).ready(function() {
var $myTextarea = $('#myTextarea');
$('input.typeahead').typeahead({
source: function (query, process) {
$.ajax({
url: '/test/typehead/data.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + query,
success: function(data) {
console.log(data);
process(data);
}
});
},
updater: function(item) {
$myTextarea.append(item, ' ');
return '';
}
});
});发布于 2013-09-19 16:58:29
jQuery(function ($) {
$('.typeahead').typeahead({
source: function (query, process) {
return $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "url",
data: '{ "query": "' + query + '"}',
dataType: "json",
success: function (data) {
//use data.d in case of asp.net
return process(data);
},
failure: function (response) {
alert("Failure");
},
error: function (jqXHR, textStatus, errorThrown) {
alert("There seems to be an error");
}
});
},
updater: function(item) {
$myTextarea.append(item, ' ');
return item;
}
});
});这应该会对你有所帮助,为了进一步阅读,请阅读this干杯!
https://stackoverflow.com/questions/18889978
复制相似问题