HTML5 高级程序设计——HTML5 存储

JSON格式

avaScript Object Notation 格式是一种数据交换的文本格式。

一、JSON格式有两个显著的优点,书写简单一目了然符合JavaScript的原生语法,可以由解释引擎直接处理,不用另外添加解析代码 ;

二、 JSON格式规则

每个json对值有严格规定:

1.复合类型的值只能是数组或对象,不能是函数,正则表达示对象或日期对象。

2.原始类型的值只有4种:字符串、数值(必须以十进制表示)、布尔值和null(不能使用NaN、infinity、undefined 和-Infinity)。

3.字符串必须以双引号表示,不能使用单引号。

4.对象的键名必须放在双引号里面。

5.数组或对象最后一个成员的后面不能加逗号。

三、JSON对象

JSON对象是JavaScript的原生对象,用来处理JSON格式数据。他有两个静态方法

JSON.stringify()方法:

JSON.stringify(JavaScript对象或数组);//JavaScript转换成字符串格式;

和JSON.parse()方法:

定义json字符串的方法 var strSports ='{"title":"adad","title":"adad","title":"adad"}'

JSON.parse(JSON格式字符串);//把字符串转换成JavaScript

因为是JavaScript的原生对象,所以此处必须大写。

jS中创建对象有两种:var obj = {};  var Object = new Object();

web存储

html5存储基础分两种sessionStorage(会话存储)localStorage(本地存储);(限制在5m以下)logStorage在2.5到10mb之间(各家浏览器不同)

localStorage和localStorage的区分:

操作代码完全相同,区分仅在于数据的寿命。

localStorage主要用来保存访客将来还能看到的数据。

sessionStorage保存从这个页面到下一个页面的数据。

window.sessionStorage 判断浏览器是否支持localStorage

window.localStorage 判断浏览器是否支持localStorage

 

 IndexedDB

通俗的来说就是浏览器提供的本地数据库 提供查找接口,还可建立索引(不属于关系数据库不支持SQL查询语句),接近NoSQL

(1)键值对存储

(2)异步

(3)支持事务

(4)同源限制(只能访问自身域名下的数据库不能跨域)

(5)存储空间大 一般不少于250M甚至没有上限

(6)支持二进制存储

if(window.indexedDB)判断浏览器是否支持

indexedDB.Open("数据库名称",1)1代表版本

创建person对象库

db.objectStoreNames.contains("person")判断对象仓库是否存在



var objectStore= db.createObjectStore("person",{

    (仓库的主键)keyPath:"id",

(自增列)autoincrement:true

})



objectStore.CreateIndex("name","name",{

unique:false (唯一索引)

})//-索引名字-索引在哪个字段-通过对象配置

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Book Description HTML5 is here, and with it, rich Internet applications (RIAs) take on a power, ease, scalability, and responsiveness that neither Ajax nor Comet could ever achieve. With this book, developers will learn how to use the latest cutting-edge web technology—available in the most recent versions of modern browsers—to build real-time web applications with unparalleled functionality, speed, and responsiveness. The HTML5 specification represents the next evolution—or rather, a revolution—of web communications required to build real-time applications. WebSockets and server-sent events provide not only a standard against which real-time web applications can be built, but also a socket, native to the browser, that facilitates network programming from the browser with efficient bidirectional (full-duplex) communication over a single connection. * Explains how you can create real-time HTML5 applications that tap the full potential of modern browsers * Provides practical, real-world examples of HTML5 features in action * Shows which HTML5 features are supported in current browsers and platforms What you’ll learn * How the HTML5 specification has evolved * How to design, develop, and run cutting-edge real-time web applications using new HTML5 features like WebSockets, server-sent events, cross-document messaging, geo location, storage, canvas, and video * Which features are available in browsers today and how you can run your applications in older browsers that do not support HTML5 features * How to use client-side APIs to communicate directly with back-end systems such as messaging systems, JMS brokers, XMPP servers, and online services such as Google Wave Who is this book for? This book is for developers who want to use the latest cutting-edge technology available in current browsers; developers who want to create dynamic, data-driven web applications; and developers who want to know which HTML5 features are supported in current browsers. About the Author Peter Lubbers is the Director of Documentation and Training at Kaazing Corporation, where he oversees all aspects of documentation and training. Peter also teaches a three-day HTML5 training course for Skills Matter. Prior to joining Kaazing, Peter worked as an information architect at Oracle, where he wrote many books, including the award-winning Oracle Application Server Portal Configuration Guide. At Oracle, Peter also developed documentation automation solutions and two of his inventions are patented. A native of the Netherlands, Peter served as a Special Forces commando in the Royal Dutch Green Berets. Peter lives on the edge of the Tahoe National Forest and in his spare time, he loves to run in the Sierra Nevada foothills and around Lake Tahoe (preferably in one go!). Brian Albers is the VP of development at Kaazing. Brian has over 13 years of experience in the field of User Interface technologies. Prior to joining Kaazing, Brian worked as Senior Development Manager at Oracle, where he led the planning and designing of the next generation of Oracle's UI technology—an effort publicly known as ADF Faces. During his 10 year tenure at Oracle, Brian worked primarily on mixing cutting-edge technology with large enterprise demands (internationalization, accessibility, scalability). He proposed the open source donation of ADF Faces, which ultimately became the Apache MyFaces Trinidad project. Brian also led a cross-team effort to develop a DHTML rich client and a mobile client presentation layer for Oracle's Project Fusion. Brian received a BS degree in Computer Science from the University of Texas, Austin, and a BA degree in Plan II Honors from the University of Texas, Austin. Frank Salim is a polyglot programmer with a keen interest in making life easier for his fellow coders. Frank leads WebSocket development at Kaazing. He is an open source advocate and a committer in several open source projects. Ric Smith is director of Oracle’s Fusion Middleware E20 Architect Team. Formerly, he led business and product strategy at Kaazing. Ric has also held various roles in product management, consulting, and software engineering. In addition, Ric is a frequent speaker at international events and has written articles featured in leading industry publications such as Java Developer's Journal and AJAX World Magazine.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值