|
我写了一个程序,需要将数据保存在本地tizen移动。 这是我写的代码:
- <script type="text/javascript">
- function saveData() {
- var a = document.getElementById('star');
- var b = document.getElementById('checkone');
- var c = document.getElementById('note');
- var d = document.getElementById('med');
- var e = document.getElementById('checktwo');
- var f = document.getElementById('wgt');
- var g = document.getElementById('wgt1');
- /* localStorage.getItem("a");
- localStorage.getItem("b");
- localStorage.getItem("c");
- localStorage.getItem("d");
- localStorage.getItem("e");
- localStorage.getItem("f");
- localStorage.getItem("g"); */
- /* Set the local storage item */
- if ("localStorage" in window) {
- localStorage.setItem(a, star);
- localStorage.setItem(b, checkone);
- localStorage.setItem(c, note);
- localStorage.setItem(d, med);
- localStorage.setItem(e, checktwo);
- localStorage.setItem(f, wgt);
- localStorage.setItem(g, wgt1);
- location.reload();
- alert("Date got")
- } else {
- alert("no localStorage in window");
- }
- /* Set the session storage item */
- if ("sessionStorage" in window) {
- sessionStorage.setItem(a, star);
- sessionStorage.setItem(b, checkone);
- sessionStorage.setItem(c, note);
- sessionStorage.setItem(d, med);
- sessionStorage.setItem(e, checktwo);
- sessionStorage.setItem(f, wgt);
- sessionStorage.setItem(g, wgt1);
- location.reload();
- alert("Data has been set")
- } else {
- alert("no sessionStorage in window");
- }
- window.onload = function() {
- var localhtml = "";
- var sessionhtml = "";
- /* Get the local storage item */
- for (var i = 0; i < localStorage.length; i++) {
- localhtml += "<li>" + localStorage.key(i) + " : "
- + localStorage.getItem(localStorage.key(i))
- + "</li>";
- }
- document.getElementById("localStorageData").innerHTML = localhtml;
- /* Get the session storage item */
- for (var j = 0; j < sessionStorage.length; j++) {
- sessionhtml += "<li>" + sessionStorage.key(j) + " : "
- + sessionStorage.getItem(sessionStorage.key(j))
- + "</li>";
- }
- document.getElementById("sessionStorageData").innerHTML = sessionhtml;
- }
- tizen.filesystem.resolve('/opt/apps/trial/data', function(
- dir) {
- documentsDir = dir;
- dir.listFiles(onsuccess, onerror);
- }, function(e) {
- console.log("Error" + e.message);
- }, "rw");
- }
- </script>
复制代码
在本部分中:
- tizen.filesystem.resolve('/opt/apps/trial/data', function(
- dir) {
- documentsDir = dir;
- dir.listFiles(onsuccess, onerror);
- }, function(e) {
- console.log("Error" + e.message);
- }, "rw");
- }
复制代码
试验
是应用程序Id,我不了解如何从tizen手机获得的应用程序Id。 和数据存储成功,但我无法检索存储的数据。 |
|