ajax請求得到後臺資料,前臺頁面,使用table模板然後clone,顯示錶格,,不用append拼接 “字串和HTML表格標籤”
阿新 • • 發佈:2019-02-16
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
<script type="text/javascript" src=\'#\'" /js/jquery-1.11.1.min.js"></script>
<style>
</style>
<script>
$(document).ready(function() {
//搜尋按鈕(全部搜尋和按條件搜尋)
$("#searchBtn").click(function(){
var itemname = $("#itemname").val();
var year = $("#year option :selected ").val();
//當輸入框為空,年份沒選擇,就為搜尋全部資料
if(itemname =="" && year == undefined){
$.get("<%=request.getContextPath()%>/searchAll",
function(data){
$.each(data.tasklist ,function(i,obj){
/* 獲取資料,新增給模板表格 */
$("#temp_table #temp_tr #id").text(obj.id);
$("#temp_table #temp_tr #name").text(obj.name);
$("#temp_table #temp_tr #type").text(obj.type);
$("#temp_table #temp_tr #cost").text(obj.cost);
$("#temp_table #temp_tr #state").text(obj.state);
$("#temp_table #temp_tr #date").text(obj.date);
/*複製模板表格,並插入到指定位置,引數true,表示CSS和事件也克隆 */
$("#temp_table #temp_tr").clone(true).insertAfter("#is_header");
});
});
}
});
});
</script>
</head>
<body>
<!-- 表格模板---用於處理獲取後臺資料後生成表格, -->
<div id="temp" style="display: none;">
<table id="temp_table">
<tr id="temp_tr">
<td id="id" width="5%" height="25" align="center" bgcolor="#EFFBFE">aa</td>
<td id="name" align="center" bgcolor="#EFFBFE">bb</td>
<td id="type" colspan="2" align="center" bgcolor="#EFFBFE">cc</td>
<td id="cost" align="center" bgcolor="#EFFBFE">dd</td>
<td id="date" align="center" bgcolor="#EFFBFE">ff</td>
<td id="state" align="center" bgcolor="#EFFBFE">ee</td>
<td align="left" bgcolor="#EFFBFE">
<div align="left" style="padding-left: 5px">
<div align="center">
<input name="edit" type="button" value="編輯" />
<input name="delete" type="button" value="刪除"/>
</div>
</div>
</td>
</tr>
</table>
</div>
<!-- 以下是顯示到頁面的內容-->
<table width="99%" height="25" border="0" align="center"
cellpadding="0" cellspacing="0" style="margin-bottom: 4px;">
<tr>
<td width="17" background="images/bj4.gif"><img
src="Picture/r.gif" width="16" height="16" /></td>
<td width="466" background="images/bj4.gif">張宇(學院申報者):你好!歡迎光臨,您上次登入時間是:2015-09-20
23:15:15</td>
<td width="162" align="center" background="images/bj4.gif"></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="1%" align="left" background="images/b2.jpg"><img
src="Picture/b1.jpg" width="10" height="26" /></td>
<td width="68%" background="images/b2.jpg"><table width="124"
border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="20" align="left"><img src="Picture/tz.gif"
width="10" height="16" /></td>
<td width="104" align="left" class="biao">專案搜尋</td>
</tr>
</table></td>
<td width="31%" align="right" background="images/b2.jpg"><img
src="Picture/b3.jpg" width="9" height="26" /></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="3"
cellspacing="1" bgcolor="#AEDEF4">
<tr>
<td align="center" bgcolor="#E2F7FE">
<form id="form1" name="form1" method="post"
action="<%=path%>/searchByYear">
<table width="50%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="10%" height="25" align="center">專案名稱:</td>
<td width="14%" align="left"><label> <input
name="itemname" type="text" id="itemname" size="20" />
</label></td>
<td width="6%" align="center">年份:</td>
<td width="14%" align="left"><select name="year" id="year">
<option value="">全部</option>
<option value='2009'>2009</option>
<option value='2010'>2010</option>
<option value='2011'>2011</option>
<option value='2012'>2012</option>
<option value='2013'>2013</option>
<option value='2008'>2008</option>
<option value='2014'>2014</option>
<option value='2015'>2015</option>
<option value='2016'>2016</option>
<option value='2017'>2017</option>
</select></td>
<td width="8%"><input type="button" id="searchBtn"
name="searchBtn" value="搜尋" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="5"></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="1%" align="left" background="images/b2.jpg"><img
src="Picture/b1.jpg" width="10" height="26" /></td>
<td width="68%" background="images/b2.jpg"><table width="124"
border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="20" align="left"><img src="Picture/tz.gif"
width="10" height="16" /></td>
<td width="104" align="left" class="biao">專案列表</td>
</tr>
</table></td>
<td width="31%" align="right" background="images/b2.jpg"><img
src="Picture/b3.jpg" width="9" height="26" /></td>
</tr>
</table>
<!-- 這裡是獲取後臺資料,並畫出顯示錶格 -->
<table id="is_table" width="99%" border="0" align="center"
cellpadding="3" cellspacing="1" bgcolor="#AEDEF4"
style="border: 1px solid #AEDEF4">
<tr id="is_header">
<td width="5%" height="25" align="center" bgcolor="#EFFBFE">ID</td>
<td align="center" bgcolor="#EFFBFE">專案名稱</td>
<td colspan="2" align="center" bgcolor="#EFFBFE">專案型別</td>
<td align="center" bgcolor="#EFFBFE">申請經費</td>
<td align="center" bgcolor="#EFFBFE">提交時間</td>
<td align="center" bgcolor="#EFFBFE">狀態</td>
<td align="center" bgcolor="#EFFBFE">管理操作</td>
<td height="25" bgcolor="#FFFFFF"> </td>
<td colspan="6" bgcolor="#FFFFFF"><span class='pagelink'>首頁</span>
<span class='pagelink'>上一頁</span> <span class='pagelink'>下一頁</span>
<span class='pagelink'>尾頁</span> 轉到第 <input
id='jumpSelect' type='text' size='2' value='1' />頁</td>
<td bgcolor="#FFFFFF">
</td>
</tr>
</table>
</body>
</html>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
<script type="text/javascript" src=\'#\'" /js/jquery-1.11.1.min.js"></script>
<style>
</style>
<script>
$(document).ready(function() {
//搜尋按鈕(全部搜尋和按條件搜尋)
$("#searchBtn").click(function(){
var itemname = $("#itemname").val();
var year = $("#year option :selected ").val();
//當輸入框為空,年份沒選擇,就為搜尋全部資料
if(itemname =="" && year == undefined){
$.get("<%=request.getContextPath()%>/searchAll",
function(data){
$.each(data.tasklist ,function(i,obj){
/* 獲取資料,新增給模板表格 */
$("#temp_table #temp_tr #id").text(obj.id);
$("#temp_table #temp_tr #name").text(obj.name);
$("#temp_table #temp_tr #type").text(obj.type);
$("#temp_table #temp_tr #cost").text(obj.cost);
$("#temp_table #temp_tr #state").text(obj.state);
$("#temp_table #temp_tr #date").text(obj.date);
/*複製模板表格,並插入到指定位置,引數true,表示CSS和事件也克隆 */
$("#temp_table #temp_tr").clone(true).insertAfter("#is_header");
});
});
}
});
});
</script>
</head>
<body>
<!-- 表格模板---用於處理獲取後臺資料後生成表格, -->
<div id="temp" style="display: none;">
<table id="temp_table">
<tr id="temp_tr">
<td id="id" width="5%" height="25" align="center" bgcolor="#EFFBFE">aa</td>
<td id="name" align="center" bgcolor="#EFFBFE">bb</td>
<td id="type" colspan="2" align="center" bgcolor="#EFFBFE">cc</td>
<td id="cost" align="center" bgcolor="#EFFBFE">dd</td>
<td id="date" align="center" bgcolor="#EFFBFE">ff</td>
<td id="state" align="center" bgcolor="#EFFBFE">ee</td>
<td align="left" bgcolor="#EFFBFE">
<div align="left" style="padding-left: 5px">
<div align="center">
<input name="edit" type="button" value="編輯" />
<input name="delete" type="button" value="刪除"/>
</div>
</div>
</td>
</tr>
</table>
</div>
<!-- 以下是顯示到頁面的內容-->
<table width="99%" height="25" border="0" align="center"
cellpadding="0" cellspacing="0" style="margin-bottom: 4px;">
<tr>
<td width="17" background="images/bj4.gif"><img
src="Picture/r.gif" width="16" height="16" /></td>
<td width="466" background="images/bj4.gif">張宇(學院申報者):你好!歡迎光臨,您上次登入時間是:2015-09-20
23:15:15</td>
<td width="162" align="center" background="images/bj4.gif"></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="1%" align="left" background="images/b2.jpg"><img
src="Picture/b1.jpg" width="10" height="26" /></td>
<td width="68%" background="images/b2.jpg"><table width="124"
border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="20" align="left"><img src="Picture/tz.gif"
width="10" height="16" /></td>
<td width="104" align="left" class="biao">專案搜尋</td>
</tr>
</table></td>
<td width="31%" align="right" background="images/b2.jpg"><img
src="Picture/b3.jpg" width="9" height="26" /></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="3"
cellspacing="1" bgcolor="#AEDEF4">
<tr>
<td align="center" bgcolor="#E2F7FE">
<form id="form1" name="form1" method="post"
action="<%=path%>/searchByYear">
<table width="50%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="10%" height="25" align="center">專案名稱:</td>
<td width="14%" align="left"><label> <input
name="itemname" type="text" id="itemname" size="20" />
</label></td>
<td width="6%" align="center">年份:</td>
<td width="14%" align="left"><select name="year" id="year">
<option value="">全部</option>
<option value='2009'>2009</option>
<option value='2010'>2010</option>
<option value='2011'>2011</option>
<option value='2012'>2012</option>
<option value='2013'>2013</option>
<option value='2008'>2008</option>
<option value='2014'>2014</option>
<option value='2015'>2015</option>
<option value='2016'>2016</option>
<option value='2017'>2017</option>
</select></td>
<td width="8%"><input type="button" id="searchBtn"
name="searchBtn" value="搜尋" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="5"></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="1%" align="left" background="images/b2.jpg"><img
src="Picture/b1.jpg" width="10" height="26" /></td>
<td width="68%" background="images/b2.jpg"><table width="124"
border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="20" align="left"><img src="Picture/tz.gif"
width="10" height="16" /></td>
<td width="104" align="left" class="biao">專案列表</td>
</tr>
</table></td>
<td width="31%" align="right" background="images/b2.jpg"><img
src="Picture/b3.jpg" width="9" height="26" /></td>
</tr>
</table>
<!-- 這裡是獲取後臺資料,並畫出顯示錶格 -->
<table id="is_table" width="99%" border="0" align="center"
cellpadding="3" cellspacing="1" bgcolor="#AEDEF4"
style="border: 1px solid #AEDEF4">
<tr id="is_header">
<td width="5%" height="25" align="center" bgcolor="#EFFBFE">ID</td>
<td align="center" bgcolor="#EFFBFE">專案名稱</td>
<td colspan="2" align="center" bgcolor="#EFFBFE">專案型別</td>
<td align="center" bgcolor="#EFFBFE">申請經費</td>
<td align="center" bgcolor="#EFFBFE">提交時間</td>
<td align="center" bgcolor="#EFFBFE">狀態</td>
<td align="center" bgcolor="#EFFBFE">管理操作</td>
</tr>
<!-- 克隆的模板表格,貼上到這裡 -->
<tr><td height="25" bgcolor="#FFFFFF"> </td>
<td colspan="6" bgcolor="#FFFFFF"><span class='pagelink'>首頁</span>
<span class='pagelink'>上一頁</span> <span class='pagelink'>下一頁</span>
<span class='pagelink'>尾頁</span> 轉到第 <input
id='jumpSelect' type='text' size='2' value='1' />頁</td>
<td bgcolor="#FFFFFF">
</td>
</tr>
</table>
</body>
</html>