联合县城市,采用ajax,而使用ul模拟select下拉
接待处代码
js
//采用jquery展示鼠标放到省ul下拉显示
$("#province").hover(function(){
$("#province ul").toggle();
})
//使用jquery效果展示鼠标放到城市的ul下拉展示
$("#city").hover(function(){
$("#city ul").toggle();
})
//使用jquery效果展示鼠标放到区县的ul下拉展示
$("#area").hover(function(){
$("#area ul").toggle();
})
//改变省份触发的函数
function changePro(ele){
$("#showPro").text(ele.innerText);
$("#showCity").text("市");
$("#showArea").text("区");
$("#pid").val(ele.value);
$("#cid").val("");
$("#aid").val("");
$.ajax({
url:'getAjaxJson.action',
data:{type:'city',id:ele.value},
type:'POST',
success:function(data){
var cityList = data.list;
var ulEle = $("#cities");
ulEle.children().remove();
for(var i=0;i<cityList.length;i++){
ulEle.append("<li onclick='changeCity(this)' value=" + cityList[i].cityid + "style='border: 0px'>"+cityList[i].city+"</li>");
}
}
});
}
//改变城市触发的函数
function changeCity(ele){
$("#showCity").text(ele.innerText);
$("#showArea").text("区");
$("#cid").val(ele.value);
$("#aid").val("");
$.ajax({
url:'getAjaxJson.action',
data:{type:'area',id:ele.value},
type:'POST',
success:function(data){
var areaList = data.list;
var ulEle = $("#areas");
ulEle.children().remove();
for(var i=0;i<areaList.length;i++){
ulEle.append("<li onclick='changeArea(this)' value=" + areaList[i].areaid + "style='border: 0px'>"+areaList[i].area+"</li>");
}
}
});
}
//改变区县触发的函数
function changeArea(ele){
$("#showArea").text(ele.innerText);
$("#aid").val(ele.value);
}
html代码
<span class="list_title_1 fl" id="province">
<span class="fl" id="showPro" style="font-size:18px;padding-top:5px;width:170px;float:left">省</span><img class="fl" src="${configBean.speedDomian}/images/pc/arr_down.png" width=10px height=10px/>
<ul>
<c:forEach items="${provinceList}" var="province">
<li onclick="changePro(this)" style="border: 0px" value="${province.provinceid}">${province.province}</li>
</c:forEach>
</ul>
</span>
<span class="list_title_1 fl" style="margin-left:12px;" id="city">
<span class="fl" id="showCity" style="font-size:18px;padding-top:5px;width:180px">市</span><img class="fl" src="${configBean.speedDomian}/images/pc/arr_down.png" width=10px height=10px/>
<ul id="cities">
</ul>
</span>
<span class="list_title_1 fl" style="margin-left:12px;" id="area">
<span class="fl" id="showArea" style="font-size:18px;padding-top:5px;width:180px">区</span><img class="fl" src="${configBean.speedDomian}/images/pc/arr_down.png" width=10px height=10px/>
<ul id="areas">
</ul>
</span>
模拟select下拉的css代码
.list_title_1{ width:200px; height:50px; border:1px solid #d6d6d6; line-height:34px; text-indent:10px; font-size:14px; color:#999; cursor:pointer; margin-top:-7px;}
.list_title_1 span{ width:70px; margin-left:0px;}
.list_title_1 img{ float:right; margin:15px 5px 0 0}
.list_title_1 ul{ display:none; width:200px; position:absolute; border:1px solid #d6d6d6; border-bottom:none; margin-top:34px; margin-left:-1px;}
.list_title_1 ul li{ width:100%; height:34px; line-height:36px; border-bottom:1px solid #d6d6d6; background:#fff; cursor:pointer}
.list_title_1 ul li:hover{ background:#43B1E8; color:#fff;}
获取城市,区县的java代码
public void getAjaxJson(){//此处使用的struts2的框架
try {
HttpServletResponse response = getResponse();
response.setContentType("application/json;charset=UTF-8");
PrintWriter out = response.getWriter();
String type = getRequest().getParameter("type");
String id = getRequest().getParameter("id");
Map<String,Object> map = new HashMap<String,Object>();
JSONObject jo = null;
if(type!=null&&"city".equals(type)){
hql="from cities where provinceid='" + id + "'";
List<cities> list = cdao.getListObj(hql,new cities());
map.put("type", type);
map.put("list", list);
jo = JSONObject.fromObject(map);
}else if(type!=null&&"area".equals(type)){
hql="from areas where cityid='" + id + "'";
List<areas> list = cdao.getListObj(hql,new areas());
map.put("type", type);
map.put("list", list);
jo = JSONObject.fromObject(map);
}
String str = jo.toString();
out.print(str);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//相应stuts2的相应配置文件片段
<!-- 获取省市json -->
<action name="getAjaxJson" class="action.unset.ProjectTraderAction" method="getAjaxJson">
</action>
说明 下拉的省部件放置request域内。不要把ajax内在要求
版权声明:本文博主原创文章,博客,未经同意不得转载。
联合县城市,采用ajax,而使用ul模拟select下拉的更多相关文章
- 自己用ul模拟实现下拉多选框,
模拟实现下拉多选框 效果如下 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- 用div,ul,input模拟select下拉框
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- ul -- li 模拟select下拉框
在写项目中 用到下拉框,一般用 <select name="" id=""> <option value=</option> &l ...
- ul+jquery自定义下拉选择框
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- Select下拉框使用ajax异步绑定数据
<!--前端样式--> <style> #searchs { width: 200px; position: absolute; border-top: none; margi ...
- SpringMVC之ajax+select下拉框交互常用方式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【jquery】ajax 动态 改变 select下拉框选中的值
//JS<script type="text/javascript> //ajax动态给添加原料的[商品名称]下拉框绑定selected属性 $("#origin_co ...
- ul模拟select,位置,数据,是否可输入及输入提示效果都可作为参数直接传入
转发请注明出处,虽然转发几率不大... HTML <span class="theContainer"></span> CSS body {padding: ...
- ajax处理select下拉表单
$('#gameid').change(function() { var gameid = $(this).val(); if (this.value != '') { $.ajax({ url: ' ...
随机推荐
- offsetTop和scrollTop差异
最近写组件,这两个属性的结果搞的有点晕,我检查的文件及资料,这两个性质如下面总结: 他一直在offsetLeft.offsetTop,scrollLeft.scrollTop这些方法都是非常迷茫,花一 ...
- retry policy is RetryUpToMaximumCountWithFixedSleep(maxRetries=10, sleepTime=1 SECONDS)
[root@qa bin]# hadoop fs -ls / Warning: $HADOOP_HOME is deprecated. 14/07/29 13:25:35 INFO ipc.Clien ...
- maven/eclipse搭建ssm(spring+spring mvc+mybatis)
maven/eclipse搭建ssm(spring+spring mvc+mybatis) 前言 本文旨在利用maven搭建ssm环境,而关于maven的具体内容,大家可以去阅读<Maven 实 ...
- 开源Math.NET基础数学类库使用(13)C#实现其他随机数生成器
原文:[原创]开源Math.NET基础数学类库使用(13)C#实现其他随机数生成器 本博客所有文章分类的总目录:http://www.cnblogs.com/asxiny ...
- Objective-C语言的一些基础特性
OC与C++.Java等面向对象语言有很多的类似之处,不过在很多方面也是有所差别的.若是用过某一种面向对象语言,那么就很容易理解OC语言所用的范式和模板了.但是在语法使用上,也许会显得陌生.因为OC语 ...
- hdu4185 Oil Skimming(偶匹配)
<span style="font-family: Arial; font-size: 14.3999996185303px; line-height: 26px;"> ...
- RecyclerView0基于使用
(转载请注明出处:http://www.kennethyo.me/post/android/recyclerviewchu-ji-shi-yong) RecyclerView是Android在v7包中 ...
- ecshop广告调用方法
在简单地概括ecshop广告调用该方法,已发表在博客上,在这里,我们总结了以下 :就是官方默认的方法.先加入广告位,然后加入模板的广告位区域,再在将两者相应上. 1.后台 > 广告管理 > ...
- Javascript入门视频教程
1,第一节 http://pan.baidu.com/play/video#video/path=%2F%E6%95%99%E5%AD%A61.mov&t=-1 2,第二节 http://pa ...
- HDU 3037 Saving Beans (Lucas法则)
主题链接:pid=3037">http://acm.hdu.edu.cn/showproblem.php?pid=3037 推出公式为C(n + m, m) % p. 用Lucas定理 ...