簡體   English   中英

jQuery Dependent Dropdown可以在准備好文檔時加載

[英]Jquery Dependent Dropdown to load on document ready

您好,我有一個關於國家/地區和城市的下拉菜單,我想在文檔就緒函數中基於國家/地區加載州和城市,我試圖將document.ready(function())

但沒有任何效果,請更新我如何使用此功能

我的代碼在這里

   function showState(sel) {
    var country_id = sel.options[sel.selectedIndex].value;  
    $("#output1").html( "" );
    $("#output2").html( "" );
    if (country_id.length > 0 ) { 

     $.ajax({
            type: "POST",
            url: "fetch_state.php",
            data: "country_id="+country_id,
            cache: false,
            beforeSend: function () { 
                $('#output1').html('<img src="images/loading.gif">');
            },
            success: function(html) {    
                $("#output1").html( html );
            }
        });
    }
}

function showCity(sel) {
    var state_id = sel.options[sel.selectedIndex].value;  
    if (state_id.length > 0 ) { 
     $.ajax({
            type: "POST",
            url: "fetch_city.php",
            data: "state_id="+state_id,
            cache: false,
            beforeSend: function () { 
                $('#output2').html('<img src="images/loading.gif">');
            },
            success: function(html) {    
                $("#output2").html( html );
            }
        });
    } else {
        $("#output2").html( "" );
    }
}

您可以在“城市/州選擇”部分嘗試selectize.js

暫無
暫無

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

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