天天看點

jquery三級關聯模糊查詢_利用jquery的三級關聯

$.each(arrData,function(index,value){})周遊數組

* {

margin: 0;

padding: 0;

list-style: none;

text-decoration: none;

}

">

$(document).ready(function () {

function objInit(obj){//初始化選擇項

return $(obj).html("請選擇");

}

var arrdata = {//定義一個數組儲存相關資料

江西省:{

南昌市: ["文港","進賢"],

贛州: ["信豐","李渡"]

},

福建省:{

龍岩: ["永定區","新羅區"],

廈門: ["思明區","集美區"]

},

河北省:{

秦皇島: ["海港區","開發區"],

唐山: ["盧龍","昌黎"]

}

}

//周遊數組對象

$.each(arrdata,function(pF){

$("#selF").append(""+pF+"");

$("#selF").on("change",function(){

objInit("#selT");

objInit("#selC");

$.each(arrdata,function(pF,pS){

// console.log(pF);

// console.log(pS);

if($("#selF option:selected").text()== pF){

//周遊數組對象,

$.each(pS,function(pT,pC){

$("#selT").append(""+pT+"");

})

//

$("#selT").on("change",function(){

objInit("#selC");

//周遊數組對象,

$.each(pS,function(pT,pC){

if($("#selT option:selected").text()==pT){

$.each(pC,function(index,value){

$("#selC").append(""+pC[index]+"");

})

}

})

})

}

})

})

})

$(".btn").on("click",function(){

var strValue="您選擇的位址為:";

strValue += $("#selF option:selected").html();

strValue += " ";

strValue += $("#selT option:selected").html();

strValue += " ";

strValue += $("#selC option:selected").html();

$(".clsTip").html(strValue);

})

})

下拉清單框事件的應用

省份:請選擇

市:請選擇

區縣:請選擇