[英]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.