<script language="JavaScript">
<!--
var hw_selecttext ="网络设备|路由器*服务器|DELL*应用系统|操作系统*系统软件|win98^win2k^winxp"
//如果文本与值不同,请输入在文本后加上@值,如:北京@010|东城@001^西城@002
var TheSplit1 = "*" //北京与上海的分隔符
var TheSplit2 = "|" //北京与东城的分隔符
var TheSplit3 = "^" //东城与西城的分隔符
var TheSplit4 = "@" //文本与值的分隔符,可以省略
var hwallselecttext = hw_selecttext
var hwdefault_value = ""
//默认值,在值有相同时有bug。
document.write('<select name="hw_1" onChange = "hw_select()"></select> <select name="hw_2" onChange = "hw_select()"></select> <input class="input" size="15" type="input" value="'+hwdefault_value+'" name="hw">\n');
var hwallselecttextarr
hwallselecttextarr = hwallselecttext.split(TheSplit1)
hwArraylength = hwallselecttextarr.length
var hwwhere = new Array(hwArraylength);
hwwhere[0]= new hw_comefrom("请选择@","请选择@");
for (var hwl=0;hwl<hwArraylength;hwl++)
{
eval(hwwhere[hwl+1] = new hw_comefrom(hwallselecttextarr[hwl].split(TheSplit2)[0],hwallselecttextarr[hwl].split(TheSplit2)[1]))
}
function hw_comefrom(hwSelect_s1,hwSelect_s2) { this.hwSelect_s1 = hwSelect_s1; this.hwSelect_s2 = hwSelect_s2; }
function hw_select()
{
with(document.all.hw_1)
{
var hwSelect_s12 = options[selectedIndex].value;
}
for(hwi = 0;hwi < hwwhere.length;hwi ++)
{
if (hwwhere[hwi].hwSelect_s1.indexOf(TheSplit4)!=-1)
{
var hwThisV = hwwhere[hwi].hwSelect_s1.split(TheSplit4)[1]
}
else
{
var hwThisV = hwwhere[hwi].hwSelect_s1
}
if (hwThisV == hwSelect_s12)
{
hwSelect_s13 = (hwwhere[hwi].hwSelect_s2).split(TheSplit3);
for(hwj = 0;hwj < hwSelect_s13.length;hwj++)
{
with(document.all.hw_2)
{
length = hwSelect_s13.length;
if (hwSelect_s13[hwj].indexOf(TheSplit4)!=-1)
{
options[hwj].text = hwSelect_s13[hwj].split(TheSplit4)[0]
options[hwj].value = hwSelect_s13[hwj].split(TheSplit4)[1]
}
else
{
options[hwj].text = hwSelect_s13[hwj];
options[hwj].value = hwSelect_s13[hwj];
}
var hwSelect_s14=options[selectedIndex].value;
}
}
break;
}
}
document.all.hw.value=hwSelect_s12+""+hwSelect_s14;
}
function hw_init()
{
with(document.all.hw_1)
{
length = hwwhere.length;
var hwm = 0
for(hwk=0;hwk<hwwhere.length;hwk++)
{
if (hwwhere[hwk].hwSelect_s1.indexOf(TheSplit4)!=-1)
{
options[hwk].text = hwwhere[hwk].hwSelect_s1.split(TheSplit4)[0];
options[hwk].value = hwwhere[hwk].hwSelect_s1.split(TheSplit4)[1];
if (hwdefault_value.indexOf(hwwhere[hwk].hwSelect_s1.split(TheSplit4)[1])!=-1){hwm = hwk}
}
else
{
options[hwk].text = hwwhere[hwk].hwSelect_s1;
options[hwk].value = hwwhere[hwk].hwSelect_s1;
if (hwdefault_value.indexOf(hwwhere[hwk].hwSelect_s1)!=-1){hwm = hwk}
}
}
selectedIndex = hwm
}
with(document.all.hw_2)
{
var hwn = 0
hwSelect_s13 = (hwwhere[hwm].hwSelect_s2).split(TheSplit3);
length = hwSelect_s13.length;
for(hwl=0;hwl<length;hwl++)
{
if (hwSelect_s13[hwl].indexOf(TheSplit4)!=-1)
{
options[hwl].text = hwSelect_s13[hwl].split(TheSplit4)[0];
options[hwl].value = hwSelect_s13[hwl].split(TheSplit4)[1];
if (hwdefault_value.indexOf(hwSelect_s13[hwl].split(TheSplit4)[1])!=-1){hwn = hwl}
}
else
{
options[hwl].text = hwSelect_s13[hwl];
options[hwl].value = hwSelect_s13[hwl];
if (hwdefault_value.indexOf(hwSelect_s13[hwl])!=-1){hwn = hwl}
}
}
selectedIndex = hwn
}
}
hw_init();
我要把这个二级下拉菜单运用到页面中去怎么实现呢?
页面中的select代码怎么写呢?我直接这样<select name="hw_1" onChange = "hw_select()"></select>没效果 请高手指教
郁闷怎么没效果啊,点击下面查看效果http://web.9612.org/seal/example/select.asp
[此贴子已经被作者于2006-7-12 14:14:03编辑过]