簡體   English   中英

Jquery:可以動態更改自動完成小部件的來源嗎?

[英]Jquery: Possible to dynamically change source of Autocomplete widget?

問候,

我正在使用官方的Autocomplete 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
}); 
});

嘗試實際更改change事件上自動完成的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 );
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM