asp下拉列表如何跳转!

来源:百度知道 编辑:UC知道 时间:2024/05/26 01:47:41
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='products.asp"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>

<select name="cid" id="cid" onchange="MM_jumpMenu('parent',this,0)">
<%
Response.Write("<option value="""">请选择分类</option>")
if rs1.eof and rs1.bof Then
response.write("<option value="""">请先添加分类</option>")
else
while not rs1.eof
response.write("<option")
response.write(">" & rs1("cname") & "</option>")
rs1.movenext
wend
end if
%>

1 因为你的select下拉菜单OPTION中没有没有输出值,因此JS中应该用selObj.options[selObj.selectedIndex].text
2 地址重定向中"products.asp"需要这么写:"products.asp?cid=",否则就会无法找到网页了
完整如下:

<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location.href='products.asp?cid="+selObj.options[selObj.selectedIndex].text+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>

===================================
以下代码在选择的数据有效时(非"请先添加分类"和"请选择分类'"),显示选择的分类的值:
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){
var dt=selObj.options[selObj.selectedIndex].text;
if(dt.toString()=='请选择分类'||dt.toString()=='请先添加分类'){
return false;}
else
{
alert(dt.toString());
}
}

//-->
&