联动下啦的实现

来源:互联网 发布:js遍历dom树 编辑:程序博客网 时间:2024/04/26 21:59
  Issuer:</label></td><td colspan="4"><select  class="SelectWideWidth" name="prov" id="selIssuerProvince" onchange="porvSelect(-1)">  </select>                          <select  class="SelectWideWidth" name="issuerId" id="selissuer" style="margin-left:30px; width:270px">                          </select></td>



$.ajax({type : "POST", // 提交方式url : "ajax/loadIssuerProvince.action?id="+$("#provId").val(), // 提交的页面dataType : "json", // 类型success : function(result) {$("#selIssuerProvince option").each(function() {$(this).remove(); // 移除原有项});$("<option value=''>----Blank----</option>").appendTo("#selIssuerProvince"); // 添加一个默认项$(result).appendTo("#selIssuerProvince");}});


function porvSelect(strid) {var code = $("#selIssuerProvince").val();if(code==null){code=$("#provId").val();}var id = strid;$.ajax({type : "POST", // 提交方式url : "ajax/loadIssuer?code="+code+"&id="+id, // 提交的页面dataType : "json", // 类型success : function(result) {$("#selissuer option").each(function() {$(this).remove(); // 移除原有项});$("<option value=''>----Blank----</option>").appendTo("#selissuer"); // 添加一个默认项$(result).appendTo("#selissuer");}});}

@Action(value = "loadIssuerProvince", results = { @Result(type = "json", params = {"contentType", "text/html", "root", "result" }) })public String loadIssuerProvince() {String id = request.getParameter("id");StringBuffer str = new StringBuffer();List<Map<String, Object>> list = pservice.getIssuerProvices();for (int i = 0; i < list.size(); i++) {str.append("<option value='");str.append(list.get(i).get("PROVINCE_ID"));str.append("' ");if (list.get(i).get("PROVINCE_ID").toString().equals(id)) {str.append(" selected='selected'");}str.append("");str.append(">");// str.append("#");str.append(list.get(i).get("name"));// str.append("#");str.append("</option>");}result = str + "";return SUCCESS;}

@Action(value = "loadIssuer", results = { @Result(type = "json", params = {"contentType", "text/html", "root", "result" }// root<会带外引号>// includeProperties Result不带字符引号// excludeProperties 返回所有的属性) })public String loadIssuer() {String code = request.getParameter("code");int id = -1;try {id = Integer.parseInt(request.getParameter("id"));} catch (Exception e) {// TODO: handle exception}StringBuffer str = new StringBuffer();List<IsicIssuer> list = issuerService.findIsicIssuerList(code, null);for (int i = 0; i < list.size(); i++) {str.append("<option value='");str.append(list.get(i).getIssuerId());str.append("' ");if (list.get(i).getIssuerId() == id) {str.append("selected='selected' ");}str.append(">");// str.append("#");str.append(list.get(i).getIssuer_name());// str.append("#");str.append("</option>");}result = str + "";return SUCCESS;}