CSDN博客

img qfljm

封装好的二级链动SELECT

发表于2004/10/10 2:38:00  750人阅读

分类: -3- javascript

<HTML><HEAD>
<TITLE>无标题文档</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<STYLE TYPE="text/css"><!--
BODY, TD, SELECT{FONT-SIZE:9pt; FONT-FAMILY:"宋体";}
--></STYLE>
<script language="javascript" defer>
var aData1 = new Array();
 aData1[0] = ['北京', '北京一|1', '北京二|2', '北京三|3'];
 aData1[1] = ['上海', '上海一|4', '上海一|5', '上海一|6'];
 aData1[2] = ['深圳', '深圳一|7', '深圳一|8', '深圳一|9'];
var aData2 = new Array();
 aData2[0] = ['电脑', '电脑一|1', '电脑一|2', '电脑一|3'];
 aData2[1] = ['冶金', '冶金一|4', '冶金一|5', '冶金一|6'];
 aData2[2] = ['建筑', '深圳一|7', '深圳一|8', '冶金一|9'];
/*
数据格式如上,可以自行用后台生成该数组.如:
'北京一|1'
"|"号前面是文本,之后则是对应的VALUE.
*/

/*该程序以封装,自行按需要修改,扩展.*/
function TowSelect(){
 this.Dadas='';
 this.objSEL1=form1.s1;
 this.objSEL2=form1.s2;
 this.Window_Onload=function(){  //初始化北京地区数据
  for (var i=0; i<this.Dadas.length; i++){
   this.objSEL1.options.add(new Option(this.Dadas[i][0], i));
   }
  this.Select_Select(0);
 };
 this.Select_Select=function(v){  //用于按S1传过来的值初始S2的列表
  this.objSEL2.options.length = 0;
  for (var i=1; i<this.Dadas[v].length; i++)
   this.objSEL2.options.add(new Option(this.Dadas[v][i].split('|')[0], this.Dadas[v][i].split('|')[1]));
 };
 this.getValue=function(){   //获取S1和S2的所选定的值
  return {
   S1Value: this.objSEL1.value,
   S2Value: this.objSEL2.value,
   S1Text:  this.objSEL1.options[this.objSEL1.selectedIndex].text,
   S2Text:  this.objSEL2.options[this.objSEL2.selectedIndex].text
   }
 };
};
var TS=new TowSelect(); //实例化地区数据
 TS.Dadas=aData1;
 TS.Window_Onload();

var TE=new TowSelect(); //实例化专业数据
 TE.Dadas=aData2;
 TE.objSEL1=form1.e1;
 TE.objSEL2=form1.e2;
 TE.Window_Onload();
</script>
</HEAD>

<BODY bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="50">
<center>
 <form name="form1">
  <DIV>
   <select name="s1" size="1" onChange="TS.Select_Select(this.value);"></select>
   <select name="s2" size="1"></select>
   <input type="button" value="显示当前选定的value" onclick="alert('S1='+TS.getValue().S1Value+' , S2='+TS.getValue().S2Value)" />
   <input type="button" value="显示当前选定的text " onclick="alert('S1='+TS.getValue().S1Text+' , S2='+TS.getValue().S2Text)" />
  </DIV>
 <br /><br /><br />
  <DIV>
   <select name="e1" size="1" onChange="TE.Select_Select(this.value);"></select>
   <select name="e2" size="1"></select>
   <input type="button" value="显示当前选定的value" onclick="alert('E1='+TE.getValue().S1Value+' , E2='+TE.getValue().S2Value)" />
   <input type="button" value="显示当前选定的text " onclick="alert('E1='+TE.getValue().S1Text+' , E2='+TE.getValue().S2Text)" />
  <DIV>
 </form>
</center>
</BODY>
</HTML>

阅读全文
0 0

相关文章推荐

img
取 消
img