单击时 jQuery 自动完成将整个列表获取到输入
我正在使用 jQuery 进行自动完成,当我单击列表中的 1 个项目时,输入会获取列表中的所有项目(甚至是
这是我调用的脚本
if($_GET['q']) {
$queryString = $db->real_escape_string($_GET['q']);
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM .... WHERE name LIKE '%$queryString%'");
if($query) {
while ($result = $query ->fetch_object()) {
echo "<li>$result->name</li>";
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
这就是 jQuery
<script type="text/javascript">
$(function() {
$("#ac3").autocomplete({
url:'searchcond.php',
select: function(event, ui) {
console.dir(ui);
event.preventDefault();
$("#ac3").text(ui.item.label);
}
});
});
</script>
另外,当我输入某些内容时,它没有得到它。我必须快速输入才能得到正确的查询
I am using jQuery to do an autocomplete and when I click 1 item on the list the input gets all the items of the list(even the < li >..< /li >)
This is the script which I call
if($_GET['q']) {
$queryString = $db->real_escape_string($_GET['q']);
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM .... WHERE name LIKE '%$queryString%'");
if($query) {
while ($result = $query ->fetch_object()) {
echo "<li>$result->name</li>";
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
And this is the jQuery
<script type="text/javascript">
$(function() {
$("#ac3").autocomplete({
url:'searchcond.php',
select: function(event, ui) {
console.dir(ui);
event.preventDefault();
$("#ac3").text(ui.item.label);
}
});
});
</script>
Also when I type something it does not get it. I have to type it fast to get the correct query
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我记得 jquery 自动完成只需要一个键|值列表(每行一个)响应,而不是 UL-LI 列表:
EG:
echo "$key|$value\n";
I remember that jquery autocomplete wants just a list of key|values (one per line) response and not an UL-LI list:
EG:
echo "$key|$value\n";
要修复正确的查询,您可以在搜索之前添加延迟或 minChars 选项: http ://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions
要获取文本,请尝试:
$("#ac3").text(ui.item.label.text());
To fix the correct query, you can add an option to delay or the minChars before the search: http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions
To get the text, try:
$("#ac3").text(ui.item.label.text());