table class="table table-bordered">
<thead>
<tr>
<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="prve()" /></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) {
index1 = index;
$.ajax({
url: "http://localhost:50825/api/Shopping/GetGoods2",
data: { index: index1, size: 2 },
type: "get",
dataType: "json",
success:
function (d) {
$("#tb").empty();
$(d.List).each(function () {
$("#tb").append(
'<tr>' +
'<td>' + this.Name + '</td>' +
'<td><img src="http://localhost:50825' + this.Img + '" width="80" height="60" /></td>' +
'<td>' + this.Price + '</td>' +
'<td><input id="Button1" type="button" value="加入购物车" onclick="addcar()" /></td>' +
'</tr>'
)
})
pagecount = d.PageCount;
}
})
}
load(1);

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

//cookie零时存购物车
function addcar() {
//判断cookie是否有值
if (getCookie("shopcar") == null) {
//数组类型
setCookie("shopcar", "[]");
}
//这里举个例子,将值写死
var obj = {
Name: "球鞋",
Price: "1200"
};

//获取值,此时为字符串类型
var liststr = getCookie('shopcar');
//类型转换
var list = JSON.parse(liststr);
//追加值
list.push(obj);
//保存到cookie中
setCookie("shopcar", JSON.stringify(list));
location.href = "/Default/ShopCar";
}

//取值
function setCookie(name, value) {
if (value) {
var days = 1; //定义一天
var exp = new Date();
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
// 写入Cookie, toGMTString将时间转换成字符串
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString;
}
};
//存值
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //匹配字段
if (arr = document.cookie.match(reg)) {
return unescape(arr[2]);
} else {
return null;
}
};
</script>

EF getCookie的更多相关文章

  1. %E3%80%90%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E3%80%91

    "%3Cdiv%20class%3D%22htmledit_views%22%20id%3D%22content_views%22%3E%0A%20%20%20%20%20%20%20%20 ...

  2. 你必须知道的EF知识和经验

    注意:以下内容如果没有特别申明,默认使用的EF6.0版本,code first模式. 推荐MiniProfiler插件 工欲善其事,必先利其器. 我们使用EF和在很大程度提高了开发速度,不过随之带来的 ...

  3. 采用MiniProfiler监控EF与.NET MVC项目(Entity Framework 延伸系列1)

    前言 Entity Framework 延伸系列目录 今天来说说EF与MVC项目的性能检测和监控 首先,先介绍一下今天我们使用的工具吧. MiniProfiler~ 这个东西的介绍如下: MVC Mi ...

  4. 采用EntityFramework.Extended 对EF进行扩展(Entity Framework 延伸系列2)

    前言 Entity Framework 延伸系列目录 今天我们来讲讲EntityFramework.Extended 首先科普一下这个EntityFramework.Extended是什么,如下: 这 ...

  5. EntityFramework之DetectChanges's Secrets(三)(我为EF正名)

    前言 对于应用程序开发者来说,通常不需要考虑太多对于Entity Framework中的变更追踪(change tracking),但是变更追踪和DetectChanges方法是栈的一部分,在这其中, ...

  6. ASP.NET从零开始学习EF的增删改查

           ASP.NET从零开始学习EF的增删改查           最近辞职了,但是离真正的离职还有一段时间,趁着这段空档期,总想着写些东西,想来想去,也不是很明确到底想写个啥,但是闲着也是够 ...

  7. 使用EF CodeFirst 创建数据库

    EntityFramework 在VS2015添加新建项时,选择数据->ADO.NET 实体数据模型,有一下选项 来自数据库的EF设计器,这个就是我们最常用的EntityFramework设计模 ...

  8. EF上下文对象线程内唯一性与优化

    在一次请求中,即一个线程内,若是用到EF数据上下文对象,就创建一个,这也加是很多人的代码中习惯在使用上下文对象时,习惯将对象建立在using中,也是为了尽早释放上下文对象, 但是如果有一个业务逻辑调用 ...

  9. EF里Guid类型数据的自增长、时间戳和复杂类型的用法

    通过前两章Lodging和Destination类的演示,大家肯定基本了解Code First是怎么玩的了,本章继续演示一些很实用的东西.文章的开头提示下:提供的demo为了后面演示效果,前面代码有些 ...

  10. 模仿EF,我们用JS开发的HTML5 SQLite 访问库

    今天终于有空把demo放到了RunJS上面去.请使用google chrome观看在线演示: http://sandbox.runjs.cn/show/pekbd9zb 这个库本来是我们开发的phon ...

随机推荐

  1. Window10上CLion极简配置教程

    Window10上CLion极简配置教程 1. 首先,下载安装CLion 去JB公司官网下载CLion,https://www.jetbrains.com/clion/download/#sectio ...

  2. Smartbi 日志监控工具

    用户日志-开始监控

  3. android修改frameework与service,vendor分区需要替换的文件

    1. 修改framework代码 需要将framework.jar包提供给android studio使用,并替换车机内文件(两种framework.jar不是同一文件,一个是生成文件一个是安卓目录文 ...

  4. Installing Jupyter

    https://jupyter.org/install install pip install jupyterlab config 生成配置文件 jupyter notebook --generate ...

  5. allure环境配置生成测试报告

    一.pycharm中安装下载allure:pip install allure-pytest.或者设置里面添加allure-pytest搜索安装 二.电脑中配置allure系统环境变量: allure ...

  6. 在CIMES中调用存储过程

    页面 调用步骤 DataTable dtResult = null; CustomDataAgent TODB_con = DBCenter.Create(AppSetting.Manufacturi ...

  7. ELKF搭建

    logstash cat /etc/logstash/logstash.yml |grep -v '#'path.data: /data/logstash/datapipeline.ordered: ...

  8. 【git】2.3查看提交历史

    资料来源 (1) https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4% ...

  9. 几十行代码实现简易版koa~

    application.js const http = require("http")// 洋葱模型 function compose(middleware){ return fu ...

  10. PowerShell学习笔记五_模块

    PowserShell其他技巧 1. 执行完一个ps1文件后,不回收 有一个场景,在fun.ps1中,仅仅写了一段 Funtion fun([String] input) { } 然后打开PowerS ...