HTML5本地存储在科尔多瓦

前端之家收集整理的这篇文章主要介绍了HTML5本地存储在科尔多瓦前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
HTML5本地存储在Cordova / PhoneGap中工作吗?我正在尝试使用HTML5方式和文档中指定的方式.既不工作

具体来说,我正在尝试使用ajax查询结果进行本地存储.我已经测试了查询,它的工作原理.

  1. <head>
  2. <Meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3. <Meta name="format-detection" content="telephone=no">
  4. <Meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width,height=device-height,target-densitydpi=device-dpi">
  5. <title>Hello World</title>
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript">
  7.  
  8. </script>
  9. <script type="text/javascript">
  10. $(document).ready(function () {
  11. $("form").submit(function () {
  12.  
  13. var uname = document.getElementById("username").value;
  14. var pword = document.getElementById("password").value;
  15. var postData = {
  16. username: uname,password: pword
  17. };
  18.  
  19. $.ajax({
  20. url: "http://www.yellowcabsavannah.com/test.PHP",type: "POST",data: postData,async: false,dataType: 'json',cache: false,success: function (data) {
  21. localStorage.uname = data.username;
  22. localStorage.pword = data.password;
  23. alert(localStorage.uname);
  24. }
  25. }
  26. });
  27. return false;
  28. });
  29. });
  30. </script>
  31. </head>
  32.  
  33. <body>
  34. <form action="">
  35. <input type='text' id="username" name="username" placeholder="Username">
  36. <br>
  37. <input type='password' id="password" name="password" placeholder="password">
  38. <br>
  39. <input type="submit" id="submit" value="Login">
  40. </form>
  41. </body>

解决方法

我已经使用了这样的本地存储:
  1. // To store a value
  2. window.localStorage.setItem('key',value);
  3.  
  4. // To retrieve a value
  5. value = window.localStorage.getItem('key');
  6.  
  7. // To delete a storage
  8. window.localStorage.removeItem('key');

希望有帮助.

猜你在找的HTML5相关文章