monacaを使用しています。ページを読み込んだときにlocalStorage.getItemで値を取得したいのですが、いろいろネットなどを見て試してみたのですが反応せず困っています。
もしよろしければコードを訂正または教えていただけないでしょうか?
コードは以下の通りです。
html
1<!DOCTYPE HTML> 2<html> 3<head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 6 <script src="components/loader.js"></script> 7 <script src="js/app.js"></script> 8 <link rel="stylesheet" href="components/loader.css"> 9 <link rel="stylesheet" href="css/style.css"> 10 <script> 11 ons.bootstrap(); 12 </script> 13</head> 14<body onLoad="Load();"> 15 <ons-sliding-menu var="app.slidingMenu" menu-page="menu.html" main-page="page1.html" side="left" type="overlay" max-slide-distance="200px"> 16 </ons-sliding-menu> 17 18 <form> 19 20 <input id="a" type="text" class="text-input" style=width:60%;> 21 22 <input id="b" type="text" class="text-input" style=width:60%;> 23 24 <input type="button" class="button" value="Save" onclick="Save()"/><br> 25 26 <input type="button" class="button" value="Load" onclick="Load()"/><br> 27 28 </form> 29 30</body>
javascript
1function Save() { 2 localStorage.setItem("key1",document.getElementById("a").value); 3 localStorage.setItem("key2",document.getElementById("b").value); 4} 5 6function Load() { 7 document.getElementById("a").value = localStorage.getItem("key1"); 8 document.getElementById("b").value = localStorage.getItem("key2"); 9}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2015/12/03 11:56