级联函数

function CascadeSelect(parent,selectName,selectTitle)
{
this.parent = parent;//上级
this.selectName = selectName;//Select对象名称
this.selectTitle = selectTitle;//Select对象初始标题
this.selectObject = document.all[selectName];//Select对象
this.data = new Array(); //数组,联动的数据源
this.child = null;//下级
if(this.parent!=null)
{
var me = this;
this.parent.child = me;
}

this.addOption=function(optionID,fatherID,optionValue,optionName)
{
this.data[this.data.length] = new Array(optionID,fatherID,optionValue,optionName);
}

this.cascade=function()//联动
{
/*
if(this.parent!=null)
{
var me=this;
this.parent.selectObject.onchange=function()
{
me.optionChange(this.options[this.selectedIndex].value);
}
this.parent.cascade();
}
*/
if(this.child!=null)
{
var me=this;
this.selectObject.onchange=function()
{
// alert(me.child.selectName);
me.child.optionChange(me.selectObject.options[this.selectedIndex].value);
}
this.child.cascade();
}
}

this.optionInit=function()//初始化Option
{
// alert(this.child.selectName);
this.selectObject.length=0;
this.selectObject.options[0]=new Option(this.selectTitle,'');
for(var i=0;i<this.data.length;i++)
{
this.selectObject.options[this.selectObject.length]=new Option(this.data[i][3],this.data[i][2]);
}
this.cascade();
}

this.optionChange=function (indexName)//重置Option
{
// alert(indexName);
var obj=this;
while(obj!=null)
{
obj.selectObject.length=0;
obj.selectObject.options[0]=new Option(obj.selectTitle,'');
obj=obj.child;
}
for(var i=0;i<this.data.length;i++)
{
if(this.data[i][1]==indexName)
{
this.selectObject.options[this.selectObject.length]=new Option(this.data[i][3],this.data[i][2]);
}
}
/*
alert(me.selectName + me.child.selectName);
if(me.child!=null)
{
me.child.optionChange(me.selectObject.options[this.selectedIndex].value);
}
*/
}
}

你可能感兴趣的:(function,selectobject,selectname)