我是 jquery 的初学者,我正在我的应用程序中实现 jquery ui 自动完成功能。但是当我练习它的例子时,自动填充的结果框出现在左上角。我尝试了所有可能的方法将其放在文本框中,但没有成功。请指导我,下面是代码片段:
<html>
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src ="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
console.log("here");
var keyList=[{value:"chinese" },
{value:"biryani"},
{value:"kabab" },
{value:"pizza"},
{value:"burger"},
];
$('#keyword').autocomplete({
source: keyList,
select: function(event, ui){
//$("#sugg-tag").val(ui.item.empUserRole);
console.log('select - '+ui.item.value);
}
});
});
</script>
</head>
<body>
Search keyword <input type="text" id="keyword">
</body>
</html>
最佳答案
我已经用最新的 jquery ui 检查了你的代码,它工作正常。我已经用版本“1.12.0”更新了 jquery ui。请检查以下代码段。
$(document).ready(function(){
var keyList=[{value:"chinese" },
{value:"biryani"},
{value:"kabab" },
{value:"pizza"},
{value:"burger"},
];
$('#keyword').autocomplete({
source: keyList,
select: function(event, ui){
console.log('select - '+ui.item.value);
}
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<script src ="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
Search keyword <input type="text" id="keyword">
关于javascript - jquery ui 自动完成结果框在左上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38613067/