javascript的问题(asp.net)
我实现了两个dropdownlist的联动,但是每次都刷新页面。我想用JavaScript实现无刷新但是不会求高手给写下。谢谢了...
我实现了两个dropdownlist的联动,但是每次都刷新页面。我想用JavaScript实现无刷新 但是不会 求高手给写下。 谢谢了
展开
2个回答
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>城市选择</title>
<style type="text/css">
<!--
body,td,th
{
font-family: 宋体;
font-size: 12px;
}
.selectCss
{
border:solid #FFFF00;
}
-->
</style>
<script language="javascript">
function cityJump(province)
{
var v_shanxi=new Array("汉中","咸阳","铜川","渭南","西安","商州","延安","榆林");
var v_hunan=new Array("长沙","衡阳","岳阳");
var v_shandong=new Array("青岛","烟台","潍坊","临沂");
var v_gansu=new Array("兰州","天水","平梁","张掖");
var city;
switch(province)
{
case "shanxi":
city=v_shanxi;
break;
case "hunan":
city=v_hunan;
break;
case "shandong":
city=v_shandong;
break;
case "gansu":
city=v_gansu;
break;
default:
city=v_shanxi;
}
var selectCity=document.form1.city;
var vOptions;
var len=selectCity.options.length;
for(var i=0;i<len;i++)
{
selectCity.options.remove(0);
}
for(var i=0;i<city.length;i++)
{
vOptions=document.createElement("option");
vOptions.value=city[i];
vOptions.text=city[i];
selectCity.options.add(vOptions);
}
}
</script>
</head>
<body onload="cityJump(null)">
<form name="form1" action="">
省份:
<select name="province" onchange="cityJump(this.value)" class="selectCss">
<option value="shanxi">陕西</option>
<option value="hunan">湖南</option>
<option value="shandong">山东</option>
<option value="gansu">甘肃</option>
</select>
城市:
<select name="city" class="selectCss">
</select>
</form>
</body>
</html>
我写下的这段程序不知道是不是你要的实现,先贴给你,如果有什么想法请联系我吧,希望对你有所帮助。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>城市选择</title>
<style type="text/css">
<!--
body,td,th
{
font-family: 宋体;
font-size: 12px;
}
.selectCss
{
border:solid #FFFF00;
}
-->
</style>
<script language="javascript">
function cityJump(province)
{
var v_shanxi=new Array("汉中","咸阳","铜川","渭南","西安","商州","延安","榆林");
var v_hunan=new Array("长沙","衡阳","岳阳");
var v_shandong=new Array("青岛","烟台","潍坊","临沂");
var v_gansu=new Array("兰州","天水","平梁","张掖");
var city;
switch(province)
{
case "shanxi":
city=v_shanxi;
break;
case "hunan":
city=v_hunan;
break;
case "shandong":
city=v_shandong;
break;
case "gansu":
city=v_gansu;
break;
default:
city=v_shanxi;
}
var selectCity=document.form1.city;
var vOptions;
var len=selectCity.options.length;
for(var i=0;i<len;i++)
{
selectCity.options.remove(0);
}
for(var i=0;i<city.length;i++)
{
vOptions=document.createElement("option");
vOptions.value=city[i];
vOptions.text=city[i];
selectCity.options.add(vOptions);
}
}
</script>
</head>
<body onload="cityJump(null)">
<form name="form1" action="">
省份:
<select name="province" onchange="cityJump(this.value)" class="selectCss">
<option value="shanxi">陕西</option>
<option value="hunan">湖南</option>
<option value="shandong">山东</option>
<option value="gansu">甘肃</option>
</select>
城市:
<select name="city" class="selectCss">
</select>
</form>
</body>
</html>
我写下的这段程序不知道是不是你要的实现,先贴给你,如果有什么想法请联系我吧,希望对你有所帮助。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询