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); });
时间: 2024-11-13 08:36:18