var text = ""; for (i = 0; i < data.length; i++) { text += "<option value=" + i + " data-pId=" + data[i].pId + ">" + data[i].pName + "</option>"; } $(".shengf").append(text); //step2:城市 var text2 = ""; $(".shengf").change(function() { text2 = "<option>请选择城市</option>"; $(".city option").remove(); $(".zhanyd option").remove(); $(".zhanyd").append("<option>请选择专营店</option>"); var cityid = $(this).val(); var shengfs; if (cityid.length < 5) { shengfs = data[cityid].cities; for (j = 0; j < shengfs.length; j++) { text2 += "<option value=" + j + " data-cId=" + shengfs[j].cId + ">" + shengfs[j].cName + "</option>"; } //step3:店铺 var text3 = ""; $(".city").change(function() { text3 = "<option>请选择专营店</option>"; $(".zhanyd option").remove(); var shengfid = $(this).val(); if (shengfid.length < 5) { var zhanyds = shengfs[shengfid].dealers; for (z = 0; z < zhanyds.length; z++) { text3 += "<option value=" + z + " data-dCode=" + zhanyds[z].dCode + ">" + zhanyds[z].dName + "</option>"; } } $(".zhanyd").append(text3); }); } $(".city").append(text2); });
本文出自 “Pureweber技术” 博客,请务必保留此出处http://tomastong.blog.51cto.com/8722734/1697038
原文地址:http://tomastong.blog.51cto.com/8722734/1697038