SSH結(jié)合jquery實(shí)現(xiàn)三級聯(lián)動(dòng)效果
本文實(shí)例為大家分享了jquery實(shí)現(xiàn)三級聯(lián)動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下
jsp頁面部分:
<li id="floors"> <span class="title" id="floorShow">選擇樓棟:</span> <select name="build" id="build" style="width: 282px;height: 40px;" onchange="floor2()"> </select> </li> <li id="builds"> <span class="title" id="floorShow">選擇住房:</span> <select name="builds" id="floot2" style="width: 282px;height: 40px;"> </select> </li>
js部分:
function floor(){ document.getElementById("build").options.length =0; document.getElementById("floot2").options.length =0; var parentId = document.getElementById("village").value; if(parentId == 0){ }else{ $.ajax({ type : "post", url : "floor.action", data : {"parentId":parentId}, dataType : "json", success :function(data){ console.log(data); var len = data.length; var htm = "<option value='0'>請選擇</option>"; for(var i=0;i<len;i++){ htm += "<option value='"+data[i].id+"'>"+data[i].info+"</option>"; } $("#build").append(htm); } }) } } function floor2(){ document.getElementById("floot2").options.length =0; var build = document.getElementById("build").value; if(build == 0){ }else{ $.ajax({ type : "post", url : "floor2.action", data : {"parentId":build}, dataType : "json", success : function(data){ var len = data.length; var htm = "<option value='0'>請選擇</option>"; for(var i=0;i<len;i++){ htm += "<option value='"+data[i].id+"'>"+data[i].info+"</option>"; } $("#floot2").append(htm); } }) } }
struts2配置部分:
<package name="user" namespace="/" extends="json-default"> <action name="floor" class="addressInfoAction" method="floor"> <result type="json"> <param name="root">floor</param> </result> </action> <action name="floor2" class="addressInfoAction" method="floor2"> <result type="json"> <param name="root">floor2</param> </result> </action> </package>
action部分:
public String floor(){ System.out.println("這里是ajax調(diào)用"); //floor = addressInfoService.getFloor(addressInfo.getParentId()); System.out.println(addressInfo.getParentId()); floor = addressInfoService.getFloor(addressInfo.getParentId()); return SUCCESS; } public String floor2(){ System.out.println("這里是ajax的第二次調(diào)用"); System.out.println(addressInfo.getParentId()); floor2 = addressInfoService.getBuild(addressInfo.getParentId()); return SUCCESS; }
最后,一定不要忘記導(dǎo)入struts2-json-plugin-2.3.15.1.jar 這個(gè)夾包的版本也要和struts2的其他的夾包的版本一致。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java框架SSH結(jié)合Easyui控件實(shí)現(xiàn)省市縣三級聯(lián)動(dòng)示例解析
- 基于jQuery+JSON的省市二三級聯(lián)動(dòng)效果
- jquery實(shí)現(xiàn)的省市區(qū)三級聯(lián)動(dòng)
- jQuery select表單提交省市區(qū)城市三級聯(lián)動(dòng)核心代碼
- 簡單實(shí)用jquery版三級聯(lián)動(dòng)select示例
- jQuery JSON實(shí)現(xiàn)無刷新三級聯(lián)動(dòng)實(shí)例探討
- ajax.net +jquery 無刷新三級聯(lián)動(dòng)的實(shí)例代碼
- 使用jQuery+HttpHandler+xml模擬一個(gè)三級聯(lián)動(dòng)的例子
- asp.net省市三級聯(lián)動(dòng)的DropDownList+Ajax的三種框架(aspnet/Jquery/ExtJs)示例
- jquery+json 通用三級聯(lián)動(dòng)下拉列表
相關(guān)文章
springboot @Value實(shí)現(xiàn)獲取計(jì)算機(jī)中絕對路徑文件的內(nèi)容
這篇文章主要介紹了springboot @Value實(shí)現(xiàn)獲取計(jì)算機(jī)中絕對路徑文件的內(nèi)容,具有很好的參考價(jià)值,希望對大家有所幫助。2021-09-09一個(gè)JAVA小項(xiàng)目--Web應(yīng)用自動(dòng)生成Word
前段時(shí)間接到一個(gè)Web應(yīng)用自動(dòng)生成Word的需求,現(xiàn)整理了下一些關(guān)鍵步驟拿來分享一下。2014-05-05Spring MVC中使用Google kaptcha驗(yàn)證碼的方法詳解
kaptcha 是一個(gè)非常實(shí)用的驗(yàn)證碼生成工具。有了它,你可以生成各種樣式的驗(yàn)證碼,因?yàn)樗强膳渲玫?,下面這篇文章主要給大家介紹了關(guān)于Spring MVC中使用Google kaptcha驗(yàn)證碼的方法,需要的朋友可以參考借鑒,下面來一起看看吧。2017-10-10SpringBoot開發(fā)案例之打造私有云網(wǎng)盤的實(shí)現(xiàn)
這篇文章主要介紹了SpringBoot開發(fā)案例之打造私有云網(wǎng)盤的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04