gpt4 book ai didi

javascript - 如何在隐藏输入字段(类型 ="text")上使用 jQuery.autocomplete ?

转载 作者:行者123 更新时间:2023-11-28 10:09:30 24 4
gpt4 key购买 nike

我正在尝试在隐藏 div 内的文本字段上使用 jQuery 的自动完成功能。尽管输入字段获得了 ui-autocomplete-input 类,但它似乎不起作用。好像没有任何事件与我的输入绑定(bind)。

需要明确的是,代码如下所示:

<a href="#overlay" class="open-the-overlay-that-has-the-id-like-this-href-attribute">OPEN</a>

<div id="overlay" style="display:none">
<form action="/action" method="post">
<input type="text" id="my-unique-id" />
<input type="submit" />
</form>
</div>

<script type="text/javascript">
$(document).ready(function(){

$("#my-unique-id").autocomplete({
source: "search.php",
minLength: 2
});

});
</script>

此后,#my-unique-id 获得 ui-autocomplete-input 类,但没有绑定(bind)任何事件。有什么想法吗?

这是服务器端脚本,但它没有任何问题,因为在另一个领域它工作正常:

(CakePHP)

function getCity() {

$this->layout = FALSE;
$this->autoRender = FALSE;
Configure::write("debug",0);

if(isset($_GET["term"]) && !empty($_GET["term"])) {
AppModel::unbind($this->City);
preg_match_all("/(\w+)/",urldecode($_GET["term"]), $term);
$or = array();
foreach ($term[0] as $t) {
if(strtolower($t) != "jud")
$or[] = "City.name LIKE '%$t%'"; // OR City.county LIKE '%$t%'
}
$or = implode(" OR ", $or);
$cities = $this->City->find("all", array("limit"=>30, "fields"=>array("City.id", "City.name", "City.county"),"conditions"=>array($or)));
$returnArray = array();
$k = 0;
foreach($cities as $c) {
$returnArray[$k]['id'] = $c["City"]["id"];
$returnArray[$k]['label'] = $c["City"]["name"].", jud. ".$c["City"]["county"];
$returnArray[$k]['value'] = $c["City"]["name"].", jud. ".$c["City"]["county"];
$k++;
}
return json_encode($returnArray);
}
}

最佳答案

您的代码是正确的,可能有问题的是您的服务器端脚本没有返回数据,因此看起来什么也没有发生。您能发布您的服务器端脚本吗?

您还可以尝试使用本地数据源:

    var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];

$("#my-unique-id").autocomplete({
source: availableTags ,
minLength: 2
});

关于javascript - 如何在隐藏输入字段(类型 ="text")上使用 jQuery.autocomplete ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7658783/

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