答案 0 :(得分:6)
尝试
$(".typeahead").typeahead({/* typeahead options */})
.on("input", function(e) {
// do stuff with current `typeahead` `value`
var myVal = e.target.value; // `$(e.target).typeahead("val")
console.log(myVal)
});
jsfiddle http://jsfiddle.net/2reurafk/1/
答案 1 :(得分:1)
我为我的代码提供的解决方案并不容易解决,但要感谢@ guest271314
$('form#prefetch').bind("keypress", function(e) {
if (e.keyCode == 13) {
e.preventDefault();
var query = $(e.target).typeahead("val").split(" ").join("-").toLowerCase();
return window.location = baseurl+'search/'+query;
}
});