对元素的jQuery自动完成检索瓦特/ AJAX自动完成、元素、jQuery、AJAX

2023-09-10 21:33:45 作者:配角永远当不了主角

我使用的是简单的jQuery自动完成的脚本来搜索院校的文本字段。同样的脚本可以在另一页上。对有问题的网页,虽然,我检索与Ajax调用的形式,它不工作。难道我忘了什么东西,还是有一个问题,结合自动完成事件到当它插入DOM?

AJAX标记:

 <输入类型=文本级=校友NAME =alumni0ID =alumni0值=奥斯卡学院>
 

脚本:

 <脚本SRC =htt​​p://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js类型=文本/ JavaScript的>< / SCRIPT>
    <链接HREF =htt​​p://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css类型=文本/ CSS媒体=所有相对= 样式/>
    <脚本类型=文/ JavaScript的LANGUAGE =JavaScript的>
        VAR availableTags;
        $(函数(){
            availableTags = [健康科学AT尽管如此大学,......,阿比林基督教大学];
            $(校友)。自动完成({
                来源:availableTags
            });
        });
    < / SCRIPT>
 

解决方案

尝试重新绑定自动完成的事件,当你在新的窗体添加到DOM。更可能正在发生的事情是自动完成的,因为没有安装与jQuery的肝功能的新元素根本没有的情况下连接。

温故jQuery Ajax,你会有新的发现

I am using a simple jquery autocomplete script to search for colleges in a text field. This same script works on another page. On the page in question though, I retrieve the form with an ajax call and it's not working. Did I forget something or is there an issue binding the autocomplete event to the when it is inserted in the DOM?

AJAX Markup:

<input type="text" class="alumni" name="alumni0" id="alumni0" value="Academy College">

Script:

    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js" type="text/javascript"></script>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css" type="text/css" media="all" rel="stylesheet" />
    <script type="text/javascript" language="javascript">
        var availableTags;
        $(function() {
            availableTags = ["A T Still University of Health Sciences", ... ,"Abilene Christian University"];
            $(".alumni").autocomplete({
                source: availableTags
            });
        });
    </script> 

解决方案

Try rebinding the autocomplete event when you add the new form to the dom. More than likely what is happening is since autocomplete isn't attached with the jquery live function your new elements just don't have the event attached.