Dapper显示

<h2>商品列表</h2>

<a id="a">导出列表</a>

<table class="table table-bordered">
<thead>
<tr>
<td>商品图片</td>
<td>商品名称</td>
<td>商品颜色</td>
<td>商品尺码</td>
<td>商品价格</td>
<td>操作</td>
</tr>
</thead>
<tbody id="tb"></tbody>
</table>

<table class="table table-bordered">
<tr>
<td><input id="Button1" type="button" value="首页" onclick="first()" /></td>
<td><input id="Button1" type="button" value="上一页" onclick="prev()" /></td>
<td><input id="Button1" type="button" value="下一页" onclick="next()" /></td>
<td><input id="Button1" type="button" value="尾页" onclick="last()" /></td>
</tr>
</table>

<script>
var index1 = 0; //获得当前页
var pagecount = 0;
function load(index) {
daoshu();
index1 = index;
$.ajax({
url: "http://localhost:51518/api/Shop/GetGoods2",
data: { index: index, size: 2 },
type: "get",
dataType: "json",
success:
function (d) {
$("#tb").empty();
$(d.List).each(function () {
$("#tb").append(
'<tr>' +
'<td><img src="http://localhost:51518' + this.GImg + '" width="80" height="60" /></td>' +
'<td>' + this.GName + '</td>' +
'<td>' + this.GColor + '</td>' +
'<td>' + this.GSize + '</td>' +
'<td>' + this.GPrice + '</td>' +
'<td><input id="Button1" type="button" value="删除" onclick="del(' + this.GId + ')" />&nbsp;<input id="Button1" type="button" value="修改" onclick="upt(' + this.GId + ')" /></td>' +
'</tr>'
)
})
pagecount = d.PageCount;
}
})
}
load(1);

function first() {
index1 = 1;
daoshu();
load(index1);
}
function prev() {
index1--;
if (index1 == 0) {
index1 = 1;
}
daoshu();
load(index1);
}
function next() {
index1++;
if (index1 > pagecount) {
index1 = pagecount;
}
daoshu();
load(index1);
}
function last() {
daoshu();
load(pagecount);
}

//删除
function del(id) {
var obj = {
GId: id
};
$.ajax({
url: "http://localhost:51518/api/Shop/DeleteGood",
data: obj,
type: "post",
dataType: "json",
success:
function (d) {
if (d > 0) {
alert('删除成功!');
load();
}
else {
alert('删除失败!');
}
}
})
}

//修改
function upt(id) {
location.href = "/Default/Update";
document.cookie = id;
}

//导出
function daoshu() {
$("#a").prop("href", "http://localhost:51518/api/Shop/Export1?index=" + index1);
}
</script>

原文地址:https://www.cnblogs.com/CoreColor/p/13448787.html