【问题标题】:Jquery: Possible to dynamically change source of Autocomplete widget?Jquery:可以动态更改自动完成小部件的来源吗?
【发布时间】:2010-08-03 17:41:24
【问题描述】:

您好,

我正在使用官方的自动完成 jquery 小部件,并且在动态更改我通过查询字符串传递的变量 (selectType) 时遇到了麻烦。变量会根据通过选择框选择的选项而改变。

$(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
}); 
});

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    尝试实际更改更改事件上自动完成的source 选项。

    $(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 );
        });
    });
    

    【讨论】:

    • 你太棒了!!我花了三天时间试图弄清楚这一点!谢谢
    • 工作真的很棒!非常感谢!
    猜你喜欢
    • 2011-09-06
    • 2013-08-28
    • 1970-01-01
    • 2015-10-04
    • 2011-09-21
    • 2011-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多