您的位置:首页 > 其它

163----三级联动---实际开发中if嵌套过多,很少使用

2017-01-17 11:38 155 查看
$(document).ready(function(){
$("#select1").change( function() {
var id = $("#select1").val();
if(id == 1){
$.get('index.php', null, function(data){
$("#two").empty();
$("#two").append("<select id='select2'><option>请选择</opton><option value='1'>长春</opton><option value='2'>松原</opton></select>");
$("#select2").change( function() {
var page = $("#select2").val();
if(page == 1){
$("#three").empty();
$("#three").append("<select><option>双阳</opton><option>农安</opton></select>");
}else{
if(page == 2){
$("#three").empty();
$("#three").append("<select><option>乾安</opton><option>大安</opton></select>");
}
}
});
});
}else{
$.get('index.php', null, function(data){
$("#two").empty();
$("#two").append("<select id='select3'><option value='1'>大连</opton><option value='2'>旅顺</opton></select>");
$("#select3").change( function() {
var page = $("#select3").val();
if(page == 1){
$("#three").empty();
$("#three").append("<select><option>西岗</opton><option>沙河口</opton></select>");
}else{
if(page == 2){
$("#three").empty();
$("#three").append("<select><option>金州</opton><option>瓦房店</opton></select>");
}
}
});
});
}
});
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: