当前位置:   article > 正文

HTML5本地存储账号密码

HTML5本地存储账号密码

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>HTML5本地存储账号密码</title>
  7. </head>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. /* 文本禁止选中: none; */
  14. user-select: none;
  15. }
  16. body {
  17. background-color: #144756;
  18. }
  19. ::placeholder {
  20. color: #ff9f05;
  21. text-shadow: 1px 1px 1px #100000;
  22. }
  23. button {
  24. /* 鼠标移入变小手 */
  25. cursor: pointer;
  26. }
  27. button,
  28. input {
  29. border: none;
  30. outline: none;
  31. height: 32px;
  32. font-size: 20px;
  33. background-color: green;
  34. padding: 0 10px;
  35. }
  36. /* 标题开始 */
  37. .header_title {
  38. position: fixed;
  39. top: 160px;
  40. left: 80px;
  41. width: 140px;
  42. height: 66px;
  43. border-radius: 50%;
  44. img {
  45. float: left;
  46. width: 66px;
  47. height: 66px;
  48. border-radius: 50%;
  49. transition: transform 0.3s ease;
  50. &:hover {
  51. transform: scale(1.2);
  52. }
  53. }
  54. h2 {
  55. background-image: linear-gradient(to top left,
  56. rgba(0, 0, 0, 0.2),
  57. rgba(0, 0, 0, 0.2) 30%,
  58. rgba(0, 0, 0, 0));
  59. box-shadow: inset 4px 4px 4px rgba(255, 255, 255, 0.6),
  60. inset -4px -4px 5px rgba(0, 0, 0, 0.6);
  61. text-shadow: 0px 1px 0px #999,
  62. 0px 2px 0px #888,
  63. 0px 3px 0px #777,
  64. 0px 4px 0px #666,
  65. 0px 5px 0px #555,
  66. 0px 6px 0px #444,
  67. 0px 7px 0px #333,
  68. 0px 8px 7px #001135;
  69. /* letter-spacing: -8px; */
  70. color: #ffffff;
  71. background-color: #f30303;
  72. border-radius: 50%;
  73. background-image: linear-gradient(to top left,
  74. rgba(0, 0, 0, 0.2),
  75. rgba(0, 0, 0, 0.2) 30%,
  76. rgba(0, 0, 0, 0));
  77. box-shadow: inset 4px 4px 4px rgba(255, 255, 255, 0.6),
  78. inset -4px -4px 5px rgba(0, 0, 0, 0.6);
  79. border: 0px solid black;
  80. }
  81. }
  82. /* 标题结束 */
  83. /* 查看按钮开始 */
  84. .search_text {
  85. position: relative;
  86. top: 2px;
  87. left: 345px;
  88. /* 首页按钮 开始*/
  89. .home_page {
  90. position: absolute;
  91. top: 0px;
  92. left: -200px;
  93. background-color: #4CAF50;
  94. color: white;
  95. border: 1px solid #4CAF50;
  96. &:hover {
  97. background-color: #ddd;
  98. color: rgb(245, 5, 5);
  99. }
  100. }
  101. a {
  102. font-size: 22px;
  103. float: left;
  104. margin: 0 15px;
  105. text-decoration: none;
  106. transition: background-color .3s;
  107. border: 1px solid #ddd;
  108. color: rgb(252, 232, 130);
  109. &:hover:not(.home_page) {
  110. background-color: #ddd;
  111. font-size: 26px;
  112. color: rgb(255, 255, 255);
  113. }
  114. }
  115. /* 首页按钮 结束*/
  116. input {
  117. border-radius: 50px;
  118. z-index: 5;
  119. box-shadow: 0px 0px 24px rgba(253, 253, 253, 0.333);
  120. }
  121. button {
  122. position: absolute;
  123. top: 0.5px;
  124. left: 203px;
  125. height: 30px;
  126. border-radius: 0 50px 50px 0;
  127. background-color: rgb(255, 0, 0);
  128. color: #ffffff;
  129. &:hover {
  130. background-color: rgb(7, 7, 7);
  131. color: #ff0101;
  132. }
  133. &:active {
  134. background-color: rgba(255, 209, 3, 0.986);
  135. color: #fcf9f9;
  136. box-shadow: inset -2px -2px 3px rgba(255, 255, 255, 0.6),
  137. inset 2px 2px 3px rgba(0, 0, 0, 0.6);
  138. }
  139. }
  140. span {
  141. color: #fffdfd;
  142. text-shadow: 1px 1px 1px #100000;
  143. }
  144. }
  145. /* 查看按钮结束 */
  146. /* 显示查看开始 */
  147. #find_result {
  148. position: relative;
  149. top: 2px;
  150. left: 345px;
  151. text-shadow: 1px 1px 1px #100000;
  152. color: #fff;
  153. span {
  154. border-radius: 50px;
  155. user-select: text;
  156. color: rgb(254, 255, 254);
  157. padding: 0 10px;
  158. background-color: rgb(255, 0, 0);
  159. font-size: 26px;
  160. }
  161. }
  162. /* 显示查看结束 */
  163. /* 新增输入框开始 */
  164. .userform {
  165. display: flex;
  166. flex-direction: column;
  167. position: absolute;
  168. top: 40px;
  169. left: 30px;
  170. input:nth-child(1) {
  171. border-radius: 48px 48px 0 0;
  172. box-shadow: 0px -8px 24px rgba(255, 255, 255, 0.333);
  173. }
  174. input:nth-child(2) {
  175. position: relative;
  176. top: 0px;
  177. left: -25px;
  178. border-radius: 50px;
  179. &::placeholder {
  180. position: relative;
  181. top: 0px;
  182. left: 25px;
  183. }
  184. background-color: rgba(1, 112, 1, 0.219);
  185. }
  186. input:nth-child(3) {
  187. border-radius: 0 0 48px 48px;
  188. box-shadow: 0px 8px 24px rgba(255, 255, 255, 0.333);
  189. }
  190. input {
  191. padding: 16px 52px 16px 35px;
  192. border: none;
  193. outline: none;
  194. width: 100%;
  195. font-size: 16px;
  196. color: #fffafa;
  197. background: linear-gradient(to right, rgba(0, 128, 0, 0.292), green);
  198. }
  199. button {
  200. position: absolute;
  201. top: 0px;
  202. left: 200px;
  203. width: 95px;
  204. height: 95px;
  205. padding: 2px;
  206. border-radius: 50%;
  207. font-size: 60px;
  208. background-color: green;
  209. box-shadow: 8px 0px 24px rgba(255, 255, 255, 0.333);
  210. &:hover {
  211. background-color: #0c333f;
  212. color: #ffffff;
  213. }
  214. &:active {
  215. background-color: rgba(255, 209, 3, 0.986);
  216. color: #fcf9f9;
  217. box-shadow: inset -2px -2px 3px rgba(255, 255, 255, 0.6),
  218. inset 2px 2px 3px rgba(0, 0, 0, 0.6);
  219. }
  220. .plus {
  221. display: block;
  222. width: 100%;
  223. height: 100%;
  224. background: linear-gradient(#fff, #fff), linear-gradient(#fff, #fff);
  225. background-size: 50% 2px, 2px 50%;
  226. background-position: center;
  227. background-repeat: no-repeat;
  228. }
  229. }
  230. button::before {
  231. content: "";
  232. position: absolute;
  233. top: 0px;
  234. left: -220px;
  235. width: 100%;
  236. height: 100%;
  237. background-color: rgb(1, 84, 1);
  238. border-radius: 50%;
  239. z-index: -1;
  240. box-shadow: -8px 0px 24px rgba(255, 255, 255, 0.333);
  241. }
  242. }
  243. /* 新增输入框结束 */
  244. /* 表格样式开始 */
  245. #list {
  246. table {
  247. position: relative;
  248. top: 3px;
  249. left: 345px;
  250. text-shadow: 1px 1px 1px #100000;
  251. color: #ffffff;
  252. td {
  253. text-align: center;
  254. font-size: 20px;
  255. button {
  256. background-color: #0c333f;
  257. border-radius: 50%;
  258. color: #ffffff;
  259. cursor: no-drop;
  260. }
  261. input {
  262. background-color: #0c333f;
  263. /* 鼠标移入变小手 */
  264. cursor: pointer;
  265. }
  266. ;
  267. }
  268. th:nth-child(3n),
  269. td:nth-child(3n) {
  270. display: none;
  271. }
  272. }
  273. td:nth-child(2n) {
  274. /*文本可以选中复制*/
  275. user-select: text;
  276. color: green;
  277. padding: 0 10px;
  278. }
  279. button,
  280. input {
  281. border: none;
  282. outline: none;
  283. height: 32px;
  284. font-size: 20px;
  285. background-color: green;
  286. padding: 0 10px;
  287. }
  288. button {
  289. background-color: rgba(255, 0, 0, 0.064);
  290. color: #ff0101;
  291. text-shadow: 1px 1px 1px #100000;
  292. /* 粗字体 */
  293. font-weight: bold;
  294. &:hover {
  295. background-color: rgb(255, 0, 0);
  296. color: #ffffff;
  297. }
  298. &:active {
  299. background-color: rgba(255, 209, 3, 0.986);
  300. color: #fcf9f9;
  301. box-shadow: inset -2px -2px 3px rgba(255, 255, 255, 0.6),
  302. inset 2px 2px 3px rgba(0, 0, 0, 0.6);
  303. }
  304. }
  305. td input {
  306. &:hover {
  307. background-color: rgb(7, 7, 7);
  308. color: #ff0101;
  309. }
  310. &:active {
  311. background-color: rgba(255, 209, 3, 0.986);
  312. color: #fcf9f9;
  313. box-shadow: inset -2px -2px 3px rgba(255, 255, 255, 0.6),
  314. inset 2px 2px 3px rgba(0, 0, 0, 0.6);
  315. }
  316. }
  317. /* 表格样式结束 */
  318. }
  319. /* 复选框样式开始 */
  320. input[type="checkbox"] {
  321. margin: 0px 10px;
  322. -webkit-appearance: none;
  323. appearance: none;
  324. width: 25px;
  325. height: 25px;
  326. position: relative;
  327. border-radius: 50%;
  328. }
  329. input[type="checkbox"]::after {
  330. content: "";
  331. width: 100%;
  332. height: 100%;
  333. border: 2px solid #e9f504;
  334. position: absolute;
  335. left: -3px;
  336. top: -3px;
  337. border-radius: 50%;
  338. }
  339. /* 设置复选框点击之后的样式*/
  340. input[type="checkbox"]:checked::after {
  341. height: 15px;
  342. width: 25px;
  343. border-top: none;
  344. border-right: none;
  345. border-radius: 0;
  346. transform: rotate(-45deg);
  347. transition: all 0.5s ease-in-out;
  348. }
  349. /* 设置复选框点击之后的样式结束*/
  350. /* 复选框样式结束 */
  351. </style>
  352. <body>
  353. <div class="header_title">
  354. <img src="file:///D:\My homepage\img\jpg\tuzi3.jpg" alt="与妖为邻">
  355. <h2>账号</h2>
  356. <h2>密码</h2>
  357. </div>
  358. <div>
  359. <form class="search_text" onsubmit="findOne(event)" action="#">
  360. <a href="file:///C:\Users\90917\Desktop\备忘录.html" class="home_page">首页</a>
  361. <input type="text" id="search_site" name="search_site" placeholder="请输入账号查看密码" />
  362. <button onclick="findOne()">查看</button> <span>提示:有个问题是账号和密码一样才能删除。虽然有点乱,但也记录了很多新知识</span>
  363. </form>
  364. <hr />
  365. <p id="find_result">
  366. </p>
  367. <hr />
  368. <form class="userform" action="#">
  369. <input type="text" id="keyname" name="keyname" class="text" placeholder="请输入账号" />
  370. <input type="password" id="sitename" name="sitename" class="text" placeholder="请输入密码" />
  371. <input type="text" id="siteurl" name="siteurl" placeholder="请输入说明" />
  372. <button onclick="save()"> <i class="plus"></i></button>
  373. </form>
  374. </div>
  375. <div id="list">
  376. </div>
  377. <script>
  378. //保存数据
  379. userAll();
  380. function save() {
  381. var site = new Object;
  382. site.keyname = document.getElementById("keyname").value;
  383. site.sitename = document.getElementById("sitename").value;
  384. site.siteurl = document.getElementById("siteurl").value;
  385. var tode = JSON.stringify(site); //将对象转换为JSON字符串
  386. localStorage.setItem(site.keyname, tode);
  387. // alert("保存成功");
  388. userAll();
  389. // 清空输入框
  390. document.getElementById("keyname").value = "";
  391. document.getElementById("sitename").value = "";
  392. document.getElementById("siteurl").value = "";
  393. }
  394. //查询数据
  395. function findOne(event) {
  396. event.preventDefault(); // 阻止表单提交
  397. var search_site = document.getElementById("search_site").value;
  398. var siteurl = localStorage.getItem(search_site);
  399. var site = JSON.parse(siteurl);
  400. var find_result = document.getElementById("find_result");
  401. find_result.innerHTML = '<span>' + search_site + '</span>' + "的密码是:" + '<span>' + site.sitename + '</span>';
  402. }
  403. //显示数据
  404. function userAll() {
  405. var list = document.getElementById("list");
  406. if (localStorage.length > 0) {
  407. var result = "<table border='1'>";
  408. result += "<tr><th>序号</th><th>账号</th><th>密码</th><th>说明</th><th> <button id='delete'>删除</button></th></tr>";
  409. for (var i = 0; i < localStorage.length; i++) {
  410. var keyname = localStorage.key(i);
  411. var tode = localStorage.getItem(keyname);
  412. try {
  413. var site = JSON.parse(tode);
  414. result += "<tr>" +
  415. "<td>" + '<button>' + (i + 1) + '</button>' + "</td>" +
  416. "<td>" + site.keyname + "</td>" +
  417. "<td>" + site.sitename + "</td>" +
  418. "<td>" + site.siteurl + "</td>" +
  419. "<td> <input type='checkbox' name='checkbox'></td>" +
  420. "</tr>";
  421. } catch (e) {
  422. console.error("Error parsing JSON for key: " + keyname, e);
  423. }
  424. }
  425. result += "</table>";
  426. list.innerHTML = result;
  427. document.body.innerHTML = document.body.innerHTML.replace(/undefined/ig, "<span style='color: red; font-size: 10px;'>$&</span>");
  428. } else {
  429. list.innerHTML = "数据为空...";
  430. }
  431. // 重新绑定删除按钮事件
  432. var deleteBtn = document.getElementById("delete");
  433. deleteBtn.onclick = function () {
  434. if (confirm("是否删除所选?")) {
  435. var checkboxes = document.getElementsByName("checkbox");
  436. for (var i = 0; i < checkboxes.length; i++) {
  437. if (checkboxes[i].checked) {
  438. var keyname = checkboxes[i].parentNode.previousElementSibling.previousElementSibling.textContent;
  439. localStorage.removeItem(keyname);
  440. checkboxes[i].parentNode.parentNode.parentNode.removeChild(checkboxes[i].parentNode.parentNode);
  441. // i--;
  442. i = i - 1; // 恢复到之前的索引
  443. }
  444. }
  445. userAll();
  446. }
  447. };
  448. // 重新绑定删除按钮事件结束
  449. };
  450. </script>
  451. </body>
  452. </html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/526703
推荐阅读
相关标签
  

闽ICP备14008679号