<html>
<head>
<script LANGUAGE="javascript">
subcity = new Array()//定义一个数组,存放所有区县信息
<%
'下面输出所有区县信息,其实利用ASP动态输出JavaScript代码,请注意和Select1.htm的内容比较
Dim db
Set db=Server.CreateObject("ADODB.Connection")
strcon="dbq="&server.mappath("city.mdb")&"driver={microsoft access driver (*.mdb)}"
db.open strcon
Dim strSql,rs,I
strSql="Select * From cities"
Set rs=db.Execute(strSql)
I=0
Do While Not rs.Eof
Response.Write "subcity[" &I &"] = new Array(""" &rs("ProID") &""",""" &rs("CityName") &""",""" &rs("CityID") &""")" &Chr(10) '最后输出一个换行符
I=I+1
rs.MoveNext
Loop
%>
//下面函数用来切换区县
function mychange(provalue) { //proValue参数传入客户选中的省份编号
document.myform.dropcity.length = 0//将city下拉框先清空
document.myform.dropcity.options[0] = new Option('==请选择区县==','')//先添加第0行
var i
for (i=0i <subcity.lengthi++) // subcity.length表示数组长度,为5
{
if (subcity[i][0] == provalue) //判断是否属于所选省份
{
//下面语句将在city下拉框最下边添加一个新项
document.myform.dropcity.options[document.myform.dropcity.length] = new Option(subcity[i][1],subcity[i][2])
}
}
}
</script>
</head>
<body>
<form name="myform" method="post">
<select name="droppro" onChange="mychange(this.options[this.selectedIndex].value)">
<option value="">==请选择省份==</option>
<%
'下面读取所有省份信息
strSql="Select * From provinces"
Set rs=db.Execute(strSql)
Do While Not rs.Eof
Response.Write "<option value='" &rs("ProID") &"'>" &rs("ProName") &"</option>"
rs.MoveNext
Loop
%>
</select>
<select name="dropcity">
<option value="">==请选择区县==</option>
</select>
</form>
</body>
</html>
看看是不是需要的。<select id="J_select">
<option value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
</select>
<script type="text/javascript">
var oSelect = document.getElementById('J_select')
var options = oSelect.options
oSelect.onchange = function(){ //选中后触发
for( var i = 0, max = options.lengthi <maxi++){
options[i].text = ''//将select中的option的值清空
}
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)