JQuery自动完成 - 三个源文件

时间:2016-08-19 13:41:13

标签: php jquery ajax autocomplete

我需要根据用户在同一页面上选择的单选按钮(3个选项)更改源文件...

source: "includes/items_<?php echo $movie_group_a ?>.php", 
source: "includes/items_<?php echo $movie_group_b ?>.php",
source: "includes/items_<?php echo $movie_group_c ?>.php",

关于如何做到这一点的任何想法

// JQUERY AUTOCOMPLETION

$(function() {
    $( "#search" ).autocomplete({
        source: "includes/items_<?php echo $movie_group_a ?>.php",
        minLength: 1, //search after one characters

        focus: function(event, ui) {
                $("#search").val(ui.item.label);
                return false;
        },

        change: function(event, ui) {
                if (!ui.item) {
                     alert("You must select an item from the drop-down list.");
                     $("#search").val('');
                     $("#search").focus();
                return false;
                }
         },

         select: function( event, ui ) {
                event.preventDefault();

                $('#search').val(ui.item.value);
                this.value = ui.item.label;
             // $('#item1').val(ui.item.value);

                $('#item1').val(ui.item.fielda);


        }
    });
});

1 个答案:

答案 0 :(得分:0)

创建一个包含自动完成功能的函数。

fileController.downloadFile is not a function

然后在条件基础上调用它,如

 function autocomplete(filename){    $( "#search" ).autocomplete({
            source: filename,
            minLength: 1, //search after one characters

            focus: function(event, ui) {
                    $("#search").val(ui.item.label);
                    return false;
            },

            change: function(event, ui) {
                    if (!ui.item) {
                         alert("You must select an item from the drop-down list.");
                         $("#search").val('');
                         $("#search").focus();
                    return false;
                    }
             },

             select: function( event, ui ) {
                    event.preventDefault();

                    $('#search').val(ui.item.value);
                    this.value = ui.item.label;
                 // $('#item1').val(ui.item.value);

                    $('#item1').val(ui.item.fielda);


            }
        });
    }