jQuery實例——jQuery實現聯動下拉列表查詢框


在查詢與列表顯示的時候經常用到聯動列表顯示,比如一級選項是國家,二級選項是省,三級是市,這樣的聯動是聯系的實時導出的,比如你不可能選擇了四川省卻在三級聯動欄中出現濟南市,這樣的聯動實現方法如下:

效果圖示:

實現源代碼:

<!DOCTaYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="keywords" content=" keywords" />
<meta name="description" content="description" />
</head>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style type="text/css">
body
{font-size:13px}
.clsInit
{width:435px;height::35px;line-height:35px;padding-left:10px}
.clsTip
{padding-top:5px;background-color:#eee;display:none}
.btn
{border:solid 1px #666;padding:2px;width:65px;float:right;margin-top:6px;margin-right:6px;filter:progid:DXImageTransform.Mcrosoft.Gradient(GraientType=0,StartColorStr=#FFFFFF,EndColorStr=#ECE9D8);}
</style>
<body>
<script type="text/javascript">
$(
function(){
function objInit(obj){
return $(obj).html('<option>請選擇</option>');
}
var arrData={
廠商1:{品牌一:
'型號1-1-1,型號1-1-2',
品牌二:
'型號1-2-1,型號1-2-2'},
廠商2:{品牌一:
'型號2-1-1,型號2-1-2',
品牌二:
'型號2-2-1,型號2-2-2'},
廠商3:{品牌一:
'型號3-1-1,型號3-1-2',
品牌二:
'型號3-2-1,型號3-2-2'}
};
$.each(arrData,
function(pF){
$(
'#selF').append('<option>'+pF+'</option>');
});
$(
'#selF').change(function(){
objInit(
'#selT');
objInit(
'#selC');
$.each(arrData,
function(pF,pS){
if($('#selF option:selected').text()==pF){
$.each(pS,
function(pT,pC){
$(
'#selT').append('<option>'+pT+'</option>');
});
$(
'#selT').change(function(){
objInit(
'#selC');
$.each(pS,
function(pT,pC){
if($('#selT option:selected').text()==pT){
$.each(pC.split(
","),function(){
$(
'#selC').append('<option>'+this+'</option>');
})
}
})

});
}
})
});
});
</script>

<div class="clsInit">

廠商:<select id="selF"><option>請選擇</option></select>
品牌:<select id="selT"><option>請選擇</option></select>
型號:<select id="selC"><option>請選擇</option></select>
<input type="button" value="查詢" id="Button1" class="btn" />
</div>
<div class="clsInit" id="divTip"></div>

</body>
</html>




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM