首页 > 代码库 > 下拉框获取关联表的信息
下拉框获取关联表的信息
用jq和ajax实现
1.在jsp页面上
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
$(function(){
$.get("productType1_findAll.action",function(data){ -------->从自己的action中查询,返回productTypeList
$.each(data.productTypeList,function(i,element){
var productId=‘${productId}‘;
if(productId==element.id){
$("#productId").append("<option value=http://www.mamicode.com/‘"+element.id+"‘selected>"+element.productTypeName+"</option>");
}else{
$("#productId").append("<option value=http://www.mamicode.com/‘"+element.id+"‘ >"+element.productTypeName+"</option>");
}
})
},"json")
})
------------------------------------------------------------------------------------------------------------------------------------
<div class="field">
<select name="productId" id="productId" class="input w50">
<option value="">请选择</option>
</select>
<div class="tips"></div>
</div>
下拉框获取关联表的信息