gpt4 book ai didi

jquery - Bootstrap typeahead 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 21:38:05 24 4
gpt4 key购买 nike

谁能帮忙找出这段代码有什么问题,预输入似乎不起作用。任何帮助都得到高度应用。

<html>
<head>
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div style="margin: 50px 50px">
<label for="product_search">Product Search: </label>
<input id="product_search" type="text" data-provide="typeahead">
</div>

<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap-typeahead.js"></script>

<script>
$(document).ready(function($) {
// Workaround for bug in mouse item selection
$.fn.typeahead.Constructor.prototype.blur = function() {
var that = this;
setTimeout(function () { that.hide() }, 250);
};

$('#product_search').typeahead({
source: function(query, process) {
return ["Deluxe Bicycle", "Super Deluxe Trampoline", "Super Duper Scooter"];
}
});
});
</script>
</body>
</html>

最佳答案

问题出在您的“源”中,源应该是一个 JSON 对象列表。你能改变吗

    $('#product_search').typeahead({
source: function(query, process) {
return ["Deluxe Bicycle", "Super Deluxe Trampoline", "Super Duper Scooter"];
}
});

收件人:

$('#product_search').typeahead({
source: [
{id: 1, name: 'Deluxe Bicycle'},
{id: 2, name: 'Super Deluxe Trampoline'},
{id: 3, name: 'Super Duper Scooter'}
]
});

告诉我它是否有效:)

关于jquery - Bootstrap typeahead 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25384901/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com