web上经常有这样的需求,一个select b内容是根据另一个select a对应的值查询而来的。每次a 选的值变化的话,都需要重新查询数据库。但是要求不能刷新页面。实现
显示页面
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body>
虚拟社区核心数据webservice<br>
<select name="sel" id="sel" onchange="getnewtext.src='test.js'">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
</select>
<span id="span">123213</span>
<script id="getnewtext"></script>
</body>
</html>
虚拟社区核心数据webservice<br>
<select name="sel" id="sel" onchange="getnewtext.src='test.js'">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
</select>
<span id="span">123213</span>
<script id="getnewtext"></script>
</body>
</html>
test.js代码(不一定非得是js,可以是jsp,asp都一样,但内容必须是javascript)
document.getelementbyid("span").innerhtml="<select><option>aaaa</option><option>234234</option></select>";
原理就是定义一个javascript脚本对象,但其内容都是每次到服务器上取得。
完美解决!

