<select class="sele" id="selProvince" name="patient.Province" onchange="loadCity(this, selCity, selArea)">
<option selected="selected">请选择</option>
<script type="text/javascript"> loadProvince(); </script>
</select> 省
<select class="sele" id="selCity" name="patient.City" disabled="disabled" onchange="loadArea(selProvince, this, selArea)"></select>市
<select class="sele" id="selArea" name="patient.County" disabled="disabled"></select> 区(县)有一个JS文件写的都是那些省市区。现在点击省份的时候就会触发Onchange事件调用那个JS中的方法。但是问题就是我要修改该页面信息,可能一进来页面,就会已经填写了地址。但是市和区都是通过点击改变省触发onchange事件之后才会出来的,现在就不能正常显示了。jspselectjs
<option selected="selected">请选择</option>
<script type="text/javascript"> loadProvince(); </script>
</select> 省
<select class="sele" id="selCity" name="patient.City" disabled="disabled" onchange="loadArea(selProvince, this, selArea)"></select>市
<select class="sele" id="selArea" name="patient.County" disabled="disabled"></select> 区(县)有一个JS文件写的都是那些省市区。现在点击省份的时候就会触发Onchange事件调用那个JS中的方法。但是问题就是我要修改该页面信息,可能一进来页面,就会已经填写了地址。但是市和区都是通过点击改变省触发onchange事件之后才会出来的,现在就不能正常显示了。jspselectjs
解决方案 »
- getOutputStream() has already been called for this response
- 亚信科技上机测试
- ftp服务器出问题了。。。帮帮忙啊
- 用ssh框架做项目出现了这样的问题,请高手解决?
- 最近刚刚学习xmlbean,没想到刚安装后,却出现了问题,望达人指教!
- hibernate日期问题
- 面对这样一个女孩,我该怎么办?
- 请教j2ee指南里面最后一个DUKE银行例子的问题
- 谁能详细解释ejb下的finder下的select语句?
- 火狐打开页面提示Description: Your request is prohibited because it would cause a cycle.
- JAVA 支付宝即时到账
- 求帮忙~~~~~~~
if($(this).val() == $("#prov").val()){
$(this).attr("selected","selected");
}
});
这样只会给省复制选中。
$("#selCity option").each(function(){
alert($(this).val());
if($(this).val() == $("#cit").val())
$(this).attr("selected","selected");
});
下面的方法进不去
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!--
北京bj
东城
西城
崇文
天津
和平
河东
河西
-->
<select id="city">
<option value="bj">北京</option>
<option value="tj">天津</option>
</select >
<select id="country"></select>
<script type="text/javascript">
var city = document.getElementById("city");
city.onchange = function() {
//document.getElementById("city").value;
var value = this.value;
var xhr;
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}else if(window.ActiveXObject) {
xhr = new ActiveXObject(
"Microsoft.XMLHttp"
);
}
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status == 200){
//xxx-xxx-xx
var content = xhr.responseText;
var countrys = content.split("-");
var c = document.getElementById("country");
var children = c.childNodes;
while(c.hasChildNodes()) {
c.removeChild(children[0]);
}
for(var i=0;i<countrys.length;i++) {
//alert("xxx");
var option = document.createElement("option");
option.innerHTML = countrys[i];
c.appendChild(option);
}
}
}
}
xhr.open("GET","cityServlet?city=" + value,true);
xhr.send(null);
}
</script>
</body>
</html>服务端: protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Map<String, List<String>> citys = new HashMap<String, List<String>>();
List<String> bList = new ArrayList<String>();
bList.add("东城");
bList.add("西城");
bList.add("崇文");
citys.put("bj", bList);
List<String> tList = new ArrayList<String>();
tList.add("和平");
tList.add("河东");
tList.add("河西");
citys.put("tj", tList);
request.setCharacterEncoding("UTF-8");
String city = request.getParameter("city");
List<String> list = citys.get(city);
String result = "";
for(String s : list) {
result += s + "-"; ///////
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
writer.print(result);
}
1.初始化操作
2.点击改变操作
你现在实现了第2步操作,第一步的操作需要你在初始化js的时候通过遍历下拉列表进行选择。
可以参考一下:http://blog.csdn.net/zhanglujie2008/article/details/8759235
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!--
北京bj
东城
西城
崇文
天津
和平
河东
河西
-->
<select id="city">
<option value="bj">北京</option>
<option value="tj">天津</option>
</select >
<select id="country"></select>
<script type="text/javascript">
var city = document.getElementById("city");
city.onchange = function() {
//document.getElementById("city").value;
var value = this.value;
var xhr;
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}else if(window.ActiveXObject) {
xhr = new ActiveXObject(
"Microsoft.XMLHttp"
);
}
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status == 200){
//xxx-xxx-xx
var content = xhr.responseText;
var countrys = content.split("-");
var c = document.getElementById("country");
var children = c.childNodes;
while(c.hasChildNodes()) {
c.removeChild(children[0]);
}
for(var i=0;i<countrys.length;i++) {
//alert("xxx");
var option = document.createElement("option");
option.innerHTML = countrys[i];
c.appendChild(option);
}
}
}
}
xhr.open("GET","cityServlet?city=" + value,true);
xhr.send(null);
}
</script>
</body>
</html>服务端: protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Map<String, List<String>> citys = new HashMap<String, List<String>>();
List<String> bList = new ArrayList<String>();
bList.add("东城");
bList.add("西城");
bList.add("崇文");
citys.put("bj", bList);
List<String> tList = new ArrayList<String>();
tList.add("和平");
tList.add("河东");
tList.add("河西");
citys.put("tj", tList);
request.setCharacterEncoding("UTF-8");
String city = request.getParameter("city");
List<String> list = citys.get(city);
String result = "";
for(String s : list) {
result += s + "-"; ///////
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
writer.print(result);
}
谢谢你 我看看