<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/upload.js"></script>
<script type="text/javascript">
function onload1(){
var action = "<%=request.getParameter("action") %>";
if (action == "addGoods"){
$("#addKind").hide();
$("#addBrand").hide();
}else if(action == "addKind"){
$("#addGoods").hide();
$("#addBrand").hide();
}else if(action == "addBrand"){
$("#addKind").hide();
$("#addGoods").hide();
}
}
function changeBrand(){
$.ajax({
url:"<%=path %>/SelectController",
type:"post",
data:{table:"goods_brand"},
success:function(json){
var select = $("#goods_brand");
$(json).each(function(){
select.append("<option>"+ this.brand_name +"</option>");
});
},
dataType:"json",
async:false
});
}
function changeKind(){
$.ajax({
url:"<%=path %>/SelectController",
type:"post",
data:{table:"goods_kind"},
success:function(json){
var select = $("#goods_kind");
$(json).each(function(){
select.append("<option>"+ this.kind_name +"</option>");
});
},
dataType:"json",
async:false
});
}
$(function() {
changeBrand();
changeKind();
});
</script>
</head>
<body onload="onload1()">
<div id="addKind">
<form action="<%=request.getContextPath() %>/Controller">
请输入新类别:<input type="text" name="kind_name" id="kind_name">
<input type="hidden" name="action" value="addKind">
<input type="submit" value="提交">
</form>
</div>
<div id="addBrand">
<form action="<%=request.getContextPath() %>/Controller">
请输入新品牌:<input type="text" name="brand_name" id="brand_name">
<input type="hidden" name="action" value="addBrand">
<input type="submit" value="提交">
</form>
</div>
<div id="addGoods">
<form action="<%=request.getContextPath() %>/Controller">
<input type=hidden name="action" value="addGoods"/>
请输入商品名称:<input type="text" name="goods_name" id="goods_name"><br>
请选择商品品牌:<select name="goods_brand" id="goods_brand" />
</select><br>
请选择商品类别:<select name="goods_kind" id="goods_kind" />
</select><br>
请输入上市时间:<input type="text" name="goods_time" id="goods_time"><br>
请输入价格:<input type="text" name="goods_price" id="goods_price"> 元<br>
请输入简介:<input type="text" name="goods_introduce" id="goods_introduce"><br>
上传图片:
<input type="file" name="fileName" onchange = "PreviewImage(this, 'imgHeadPhoto', 'divPreview')"/>
<div id="divPreview">
<img id="imgHeadPhoto" src="<%=request.getContextPath() %>/image/yuan.gif" style="width: 160px; height: 170px;border: solid 1px #d2e2e2;" alt="" />
</div>
<input type="submit" value="提交"/>
</form>
</div>
</body>
</html>
如上代码,我在select中得到的东西是undefined,找了半天没发现错误
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/upload.js"></script>
<script type="text/javascript">
function onload1(){
var action = "<%=request.getParameter("action") %>";
if (action == "addGoods"){
$("#addKind").hide();
$("#addBrand").hide();
}else if(action == "addKind"){
$("#addGoods").hide();
$("#addBrand").hide();
}else if(action == "addBrand"){
$("#addKind").hide();
$("#addGoods").hide();
}
}
function changeBrand(){
$.ajax({
url:"<%=path %>/SelectController",
type:"post",
data:{table:"goods_brand"},
success:function(json){
var select = $("#goods_brand");
$(json).each(function(){
select.append("<option>"+ this.brand_name +"</option>");
});
},
dataType:"json",
async:false
});
}
function changeKind(){
$.ajax({
url:"<%=path %>/SelectController",
type:"post",
data:{table:"goods_kind"},
success:function(json){
var select = $("#goods_kind");
$(json).each(function(){
select.append("<option>"+ this.kind_name +"</option>");
});
},
dataType:"json",
async:false
});
}
$(function() {
changeBrand();
changeKind();
});
</script>
</head>
<body onload="onload1()">
<div id="addKind">
<form action="<%=request.getContextPath() %>/Controller">
请输入新类别:<input type="text" name="kind_name" id="kind_name">
<input type="hidden" name="action" value="addKind">
<input type="submit" value="提交">
</form>
</div>
<div id="addBrand">
<form action="<%=request.getContextPath() %>/Controller">
请输入新品牌:<input type="text" name="brand_name" id="brand_name">
<input type="hidden" name="action" value="addBrand">
<input type="submit" value="提交">
</form>
</div>
<div id="addGoods">
<form action="<%=request.getContextPath() %>/Controller">
<input type=hidden name="action" value="addGoods"/>
请输入商品名称:<input type="text" name="goods_name" id="goods_name"><br>
请选择商品品牌:<select name="goods_brand" id="goods_brand" />
</select><br>
请选择商品类别:<select name="goods_kind" id="goods_kind" />
</select><br>
请输入上市时间:<input type="text" name="goods_time" id="goods_time"><br>
请输入价格:<input type="text" name="goods_price" id="goods_price"> 元<br>
请输入简介:<input type="text" name="goods_introduce" id="goods_introduce"><br>
上传图片:
<input type="file" name="fileName" onchange = "PreviewImage(this, 'imgHeadPhoto', 'divPreview')"/>
<div id="divPreview">
<img id="imgHeadPhoto" src="<%=request.getContextPath() %>/image/yuan.gif" style="width: 160px; height: 170px;border: solid 1px #d2e2e2;" alt="" />
</div>
<input type="submit" value="提交"/>
</form>
</div>
</body>
</html>
如上代码,我在select中得到的东西是undefined,找了半天没发现错误