ASP在线求助:JS关联互动如何一开始就选择

来源:百度知道 编辑:UC知道 时间:2024/07/03 13:58:43
JS代码如下:

function changeCity(){
index = form.whot.options.selectedIndex-1;
form.City.length = City[index].length;
for(var i = 0;i<City[index].length;i++)
{
var text = City[index][i].split("-");
form.City.options[i].text = text[0];
form.City.options[i].value =text[1];
}
}

var City = new Array(
new Array("大分类1","大分类2),
new Array("下分类1","下分类2")
);

使用方法如下

<select name="whot" size="1" id="whot" onChange=changeCity()>
<option selected>请选择</option>
<option value="true">大分类</option>
<option value="false">下分类</option>
</select>

上面是关联

下面开始执行关联
<select name="City" size="1" id="City">
<option selected>请选择</

给你一段代码 完全实现你的要求
自己看看
不懂给我留言

<%
Set rs_p_class_b= Server.CreateObject("ADODB.Recordset")
sql="select * from p_class_b"
rs_p_class_b.open sql,conn,1,1
if rs_p_class_b.eof and rs_p_class_b.bof then
response.write "请先添加栏目。"
response.end
else
%>
<select name="p_class_b" size="1"onchange="changelocation(document.myform.p_class_b.options[document.myform.p_class_b.selectedIndex].value)">
<option value="<%=rs_p_class_b("p_class_b_id")%>"><%=trim(rs_p_class_b("p_class_b_name"))%></option>
<%
dim selclass
selclass=rs_p_class_b("p_class_b_id")
rs_p_class_b.movenext
do while not rs_p_class_b.eof
%>
<option value="<%=rs_p_class_b("p_class_b_id")%>"><%=trim(rs_p_class_b("p_class_b_name"))%></option&