license: >
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
提供对 W3C Web 存储介面的访问
var permanentStorage = window.localStorage;
var tempStorage = window.sessionStorage;
键: 返回在指定的位置的键的名称。
getItem: 返回由指定的键标识的项。
setItem: 分配一个键控的项值。
removeItem: 删除标识由指定键的项。
清除: 中移除所有键/值对。
window.localStorage
介面实现,W3C Web 存储介面。 应用程式可以使用它来保存永久资料使用键-值对。 window.sessionStorage
介面在每个方面,除了,所有资料都被都清除应用程式关闭每次的工作方式相同。 每个资料库提供了单独的命名空间。
var keyName = window.localStorage.key(0);
window.localStorage.setItem("key", "value");
var value = window.localStorage.getItem("key");
// value is now equal to "value"
window.localStorage.removeItem("key");
window.localStorage.clear();
<!DOCTYPE html>
<html>
<head>
<title>Storage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
window.localStorage.setItem("key", "value");
var keyname = window.localStorage.key(i);
// keyname is now equal to "key"
var value = window.localStorage.getItem("key");
// value is now equal to "value"
window.localStorage.removeItem("key");
window.localStorage.setItem("key2", "value2");
window.localStorage.clear();
// localStorage is now empty
}
</script>
</head>
<body>
<h1>Example</h1>
<p>localStorage</p>
</body>
</html>
点标记法是*没有*可用的 Windows Phone 7。 一定要使用 setItem
或 getItem
,而不是直接从存储物件,如便捷键window.localStorage.someKey
.