三级联动菜单

by 清泉 22. 四月 2009 13:00

<SCRIPT LANGUAGE="JavaScript">
<!--
// --------------------------------------------------- //
// 功能:三级联动菜单
// 应用:一般情况下用于省份、城市、市区 的联动选择。
// 作者:Slam (Q#53717879)
// 日期:2007年6月4日 15:04:26
// 示例:
// <form method="post" action="">
// <select name="s1" size="1" id="s1"></select>
// <select name="s2" size="1" id="s2"></select>
// <select name="s3" size="1" id="s3">
// </form>
// <SCRIPT LANGUAGE="JavaScript">
// <!--
// var SG = new SelectGroup("s1", "s2", "s3")
// SG.IntIndex(2, 8, 10); //绑定。留空时则不绑定。
// SG = null;
// //-->
// <\/SCRIPT>
// --------------------------------------------------- //
function SelectGroup(PL, CL, AL){
 var _objPL = document.getElementById(PL);
 var _objCL = document.getElementById(CL);
 var _objAL = document.getElementById(AL);
 var strTemp = "---";
 var strVal = "0";
 var _1val = "";
 var _2val = "";
 var _3val = "";
 var _P = [];
  _P[0] = new Array("1", "A");
  _P[1] = new Array("2", "B");
  _P[2] = new Array("3", "C");
  _P[3] = new Array("4", "D");
  _P[4] = new Array("5", "E");
  _P[5] = new Array("6", "F");

 var _C = [];
  _C[0] = new Array("1", "1", "A1");
  _C[1] = new Array("1", "2", "A2");
  _C[2] = new Array("1", "3", "A3");
  _C[3] = new Array("1", "4", "A4");
  _C[4] = new Array("1", "5", "A5");
  _C[5] = new Array("2", "6", "B1");
  _C[6] = new Array("2", "7", "B2");
  _C[7] = new Array("2", "8", "B3");
  _C[3] = new Array("3", "9", "C1");
  _C[4] = new Array("3", "10", "C2");

 var _A = [];
  _A[0] = new Array("1", "1", "A1-1");
  _A[1] = new Array("1", "2", "A1-2");
  _A[2] = new Array("1", "3", "A1-3");
  _A[3] = new Array("2", "4", "A2-1");
  _A[4] = new Array("2", "5", "A2-2");
  _A[5] = new Array("6", "6", "B1-1");
  _A[6] = new Array("6", "7", "B1-2");
  _A[7] = new Array("7", "8", "B2-1");
  _A[8] = new Array("7", "9", "B2-2");
  _A[9] = new Array("8", "10", "B3-1");

 this.IntIndex = function(_PLval, _CLval, _ALval){
  _objPL.options[0] = new Option(strTemp, strVal);
  _objCL.options[0] = new Option(strTemp, strVal);
  _objAL.options[0] = new Option(strTemp, strVal);
  if (!isNaN(_PLval) && !isNaN(_CLval) && !isNaN(_ALval)){
   _1val = _PLval;
   _2val = _CLval;
   _3val = _ALval;
   _AddP();
   _AddC(_PLval);
   _AddA(_CLval);
  }
  else
  { _AddP(); }
 }

 _AddP = function(){
  if (!isNaN(_objPL)){alert("对象ID设置错误."); return false;}
  _objPL.length = 1;
  _objPL.selectedIndex = 0
  for (var i=0; i<_P.length; i++){
   var OPP = document.createElement("OPTION");
   OPP.innerHTML = _P[i][1];
   OPP.value = _P[i][0];
   _objPL.appendChild(OPP);
  }
  if (!isNaN(_1val)){
   for(var x=0; x<_objPL.length; x++){
    if (_1val==_objPL.options[x].value) _objPL.options[x].selected = true;
   }
  }
  _objPL.onchange = function(){
   _AddC(this.value);
  }
 };

 _AddC = function(load){
  if (!isNaN(_objCL) || !isNaN(_objAL)){alert("对象ID设置错误."); return false;}
  _objCL.length = 1;
  _objCL.selectedIndex = 0
  _objAL.length = 1;
  _objAL.selectedIndex = 0
  for (var i=0; i<_C.length; i++){
   if (_C[i][0]==load){
    var OPP = document.createElement("OPTION");
    OPP.innerHTML = _C[i][2];
    OPP.value = _C[i][1];
    _objCL.appendChild(OPP);
   }
  }
 

  if (!isNaN(_2val)){
   for(var x=0; x<_objCL.length; x++){
    if (_2val==_objCL.options[x].value) _objCL.options[x].selected = true;
   }
  }
  _objCL.onchange = function(){
   _AddA(this.value);
  }
 };

 _AddA = function(load){
  _objAL.length = 1;
  _objAL.selectedIndex = 0
  for (var i=0; i<_A.length; i++){
   if (_A[i][0]==load){
    var OPP = document.createElement("OPTION");
    OPP.innerHTML = _A[i][2];
    OPP.value = _A[i][1];
    _objAL.appendChild(OPP);
   }
  }

  if (!isNaN(_3val)){
   for(var x=0; x<_objAL.length; x++){
    if (_3val==_objAL.options[x].value) _objAL.options[x].selected = true;
   }
  }
 };

}//end class

//-->
</SCRIPT>
<select name="s1" size="1" id="s1">
</select>
<select name="s2" size="1" id="s2">
</select>
<select name="s3" size="1" id="s3">
</select>
<input type="button" value="GetValue" onClick="alert(s1.value + '-- ' + s2.value + '-- ' + s3.value)">
<SCRIPT LANGUAGE="JavaScript">
<!--
var s = new SelectGroup("s1","s2","s3");
s.IntIndex();
s = null;
//-->
</SCRIPT>

Tags:

JS相关技术

添加评论



(将显示你的Gravatar头像)  

biuquote
微笑得意调皮害羞酷大笑惊讶发呆喜欢可怜尴尬闭嘴噘嘴皱眉伤心抓狂呕吐坏笑漫骂发怒
Loading



Supidea.com 晨飞的梦 @ All Rights Reserved. Powered by BlogYi.NET ver:1.8.0.0. 苏ICP备09011404号

关于博主

kamau
抱着美好的理想背井离乡,这酸甜苦辣只能默默忍受。既然选择了路,就得风雨兼程……

Calendar

<<  五月 2012  >>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

在日历中查看文章

最近的评论

Comment RSS

声明

      本博所发一切破解相关附件只作学习研究交流之用,严禁用于商业用途,请在下载24小时内删除。
      本博所有网友评论不代表本博立场,版权归其作者所有。

© Copyright 2009