下面的是一个两级联动添加到列表框的例子,如果是三级联动的怎么做啊?如果省市县选择框第一个OPTION分别是“请选择省份”、“请选择市”、“请选择县”的话,怎么改呢?// sObjListID1 - 源选择框一
// sObjListID2 - 源选择框二
// tObjListID - 目标列表框
// limit - 允许向目标列表框添加的项数
// combtype - 文本组合类型:1-组合两个源选框文本,2-组合两个源选框的值
// joinchar - 源选择框一选项值与源选择框二选项值的连接字符
function AddItemToList(sObjListID1, sObjListID2, tObjListID, limit, combtype, joinchar)
{
var sObjList1, sObjList2, tObjList, selectedItem1, selectedItem2;
sObjList1 = document.getElementById(sObjListID1);
sObjList2 = document.getElementById(sObjListID2);
tObjList = document.getElementById(tObjListID); if( sObjList1 != null && sObjList2 != null && tObjList != null )
{
if( sObjList1.selectedIndex >= 0 && sObjList2.selectedIndex >= 0)
{
if( tObjList.length < limit || limit == 0 )
{
selectedItem1 = sObjList1.options[sObjList1.selectedIndex];
selectedItem2 = sObjList2.options[sObjList2.selectedIndex]; for( i=0; i<tObjList.length; i++ )
{
if( tObjList.options[i].value == selectedItem2.value)
{
alert("已经选择有该项!");
return;
}
else if( selectedItem1.value.indexOf(tObjList.options[i].value)==0 )
{
alert("已经选择了该类不限!");
return;
}
else if( tObjList.options[i].value.indexOf(selectedItem1.value)==0 )
{
alert("与已经选择的项有冲突!");
return;
}
}
switch( combtype )
{
case 1:// 组合两个源选框文本
if(sObjList1.options[sObjList1.selectedIndex].value == sObjList2.options[sObjList2.selectedIndex].value)
tObjList.options[tObjList.length] = new Option(
sObjList2.options[sObjList2.selectedIndex].text,
selectedItem2.value);
else
tObjList.options[tObjList.length] = new Option(
sObjList1.options[sObjList1.selectedIndex].text + joinchar + selectedItem2.text,
selectedItem2.value);
tObjList.options[tObjList.length-1].selected = true;
break;
case 2:// 使用源选框二的值
tObjList.options[tObjList.length] = new Option(
selectedItem2.value.replace(joinchar, ""), selectedItem2.value);
tObjList.options[tObjList.length-1].selected = true;
break;
}
}
else
{
alert("最多只能添加" + limit + "项!");
}
}
}
}
// sObjListID2 - 源选择框二
// tObjListID - 目标列表框
// limit - 允许向目标列表框添加的项数
// combtype - 文本组合类型:1-组合两个源选框文本,2-组合两个源选框的值
// joinchar - 源选择框一选项值与源选择框二选项值的连接字符
function AddItemToList(sObjListID1, sObjListID2, tObjListID, limit, combtype, joinchar)
{
var sObjList1, sObjList2, tObjList, selectedItem1, selectedItem2;
sObjList1 = document.getElementById(sObjListID1);
sObjList2 = document.getElementById(sObjListID2);
tObjList = document.getElementById(tObjListID); if( sObjList1 != null && sObjList2 != null && tObjList != null )
{
if( sObjList1.selectedIndex >= 0 && sObjList2.selectedIndex >= 0)
{
if( tObjList.length < limit || limit == 0 )
{
selectedItem1 = sObjList1.options[sObjList1.selectedIndex];
selectedItem2 = sObjList2.options[sObjList2.selectedIndex]; for( i=0; i<tObjList.length; i++ )
{
if( tObjList.options[i].value == selectedItem2.value)
{
alert("已经选择有该项!");
return;
}
else if( selectedItem1.value.indexOf(tObjList.options[i].value)==0 )
{
alert("已经选择了该类不限!");
return;
}
else if( tObjList.options[i].value.indexOf(selectedItem1.value)==0 )
{
alert("与已经选择的项有冲突!");
return;
}
}
switch( combtype )
{
case 1:// 组合两个源选框文本
if(sObjList1.options[sObjList1.selectedIndex].value == sObjList2.options[sObjList2.selectedIndex].value)
tObjList.options[tObjList.length] = new Option(
sObjList2.options[sObjList2.selectedIndex].text,
selectedItem2.value);
else
tObjList.options[tObjList.length] = new Option(
sObjList1.options[sObjList1.selectedIndex].text + joinchar + selectedItem2.text,
selectedItem2.value);
tObjList.options[tObjList.length-1].selected = true;
break;
case 2:// 使用源选框二的值
tObjList.options[tObjList.length] = new Option(
selectedItem2.value.replace(joinchar, ""), selectedItem2.value);
tObjList.options[tObjList.length-1].selected = true;
break;
}
}
else
{
alert("最多只能添加" + limit + "项!");
}
}
}
}
function AddItemToList(sObjListID1, sObjListID2, sObjListID3,tObjListID, limit, combtype, joinchar)
// sObjListID1 - 源选择框一(代表省)
// sObjListID2 - 源选择框二(代表市)
// sObjListID3 - 源选择框三(代表县)
// tObjListID - 目标列表框(右侧列表)
// limit - 允许向目标列表框添加的项数
// combtype - 文本组合类型:1-组合两个源选框文本,2-组合两个源选框的值 (这个不知道怎么组合了)
// joinchar - 源选择框一选项值与源选择框二选项值/源选择框二选项值与源选择框三选项值的连接字符 分析一下,左侧源选框应该有以下几种联动的情况:1. 省份有选择,如广东省,市不限(此时县也不限),添加后右侧列表中显示应该是:广东省或者广东省-不限2. 省份和市有选择,如广东省深圳市,县不限,添加后右侧列表中显示应该是:广东省-深圳市或者广东省-深圳市-不限4. 省市县都有选择,如广东省深圳市宝安县,添加后右侧列表中显示应该是:广东省-深圳市-宝安县注:如果省市县选择框第一个OPTION分别是“请选择省份”、“请选择市”、“请选择县”的话,对应的VALUE分别是“”、“不限”、“不限”,怎么设定省为必选项?没有选择省的话,ONCLICK添加按钮的时候,怎样写一个ALERT?请高手赐教,谢谢
┏━━━┓ ┏━━━━━━━━━━━━┓
┃广东省┃ ┃广东省-深圳市-宝安县┃
┗━━━┛ ┃ 北京市-不限 ┃
┏━━━┓ ┏━━━━━━━┓ ┃山东省-济南市-不限 ┃
┃深圳市┃ ┃添加按钮 >>>┃ ┃广东省-广州市-黄埔区┃
┗━━━┛ ┗━━━━━━━┛ ┃ ┃
┏━━━┓ ┃ ┃
┃宝安县┃ ┃ ┃
┗━━━┛ ┗━━━━━━━━━━━━┛
(上面的FUNCTION怎么改成三级联动内容的添加?)我是菜鸟,不懂JAVASCRIPT编程的,请高手赐教