Jquery:可以动态更改自动完成小部件的来源吗? [英] Jquery: Possible to dynamically change source of Autocomplete widget?

查看:96
本文介绍了Jquery:可以动态更改自动完成小部件的来源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

我正在使用官方的Autocomplete jquery小部件,并且我正在通过查询字符串动态更改变量(selectType)。变量将根据通过选择框选择的选项而改变。

I am using the official Autocomplete jquery widget and am having troubles dynamically changing a variable (selectType) I'm passing via the query string. The variable would change depending upon which option is selected via a select box.

$(function() {
var selectType = $('#selectType option:selected').attr("value");    


$("#selectType").change(function(){
    selectType = $('#selectType option:selected').attr("value");
    alert (selectType);  // alerts the right value for debugging
});

$("#address").autocomplete({
    source: "ajaxSearchForClientAddress.php?selectType="+selectType,
    minLength: 3
}); 
});


推荐答案

尝试实际更改来源更改事件的自动填充选项。

Try actually changing the source option of the autocomplete on the change event.

$(function () {
    var select = $( "#selectType" ),
        options = select.find( "option" ),
        address = $( "#address" );

    var selectType = options.filter( ":selected" ).attr( "value" );
    address.autocomplete({
        source: "ajaxSearchForClientAddress.php?selectType=" + selectType,
        minLength: 3
    });

    select.change(function () {
        selectType = options.filter( ":selected" ).attr( "value" );
        address.autocomplete( "option", "source", "ajaxSearchForClientAddress.php?selectType=" + selectType );
    });
});

这篇关于Jquery:可以动态更改自动完成小部件的来源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆