1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <title>Document</title> 7 8 <script> 9 /* 10 window 对象是由浏览器提供给我们使用的,无需自己new 11 window.可以省略不写 12 三种弹窗方式 13 alert 14 prompt 15 confirm 16 17 定时任务 18 setTimeout 19 20 history 窗口的访问历史 21 location 22 sessionStorage 用于存储一些会话级数据 (浏览器关闭,数据清除) 23 localStorage 用于存储一些持久级数据 (浏览器关闭,数据还在) 24 console 控制台 25 26 更多可见菜鸟网 27 28 29 */ 30 function fun1(){ 31 window.alert("Hello!") 32 } 33 function fun2(){ 34 var res = window.prompt("Hello, 请输入姓名") 35 console.log(res) 36 } 37 function fun3(){ 38 var res = window.confirm("确定要删除吗?") 39 console.log(res) 40 } 41 function fun4(){ 42 window.setTimeout(function (){console.log("hello")},2000) 43 } 44 45 function fun5(){ 46 //向前翻页 47 history.back() 48 } 49 function fun6(){ 50 //向后翻页 51 history.forward() 52 } 53 function fun7(){ 54 //向后翻()页 55 history.go(1) 56 } 57 58 function fun8(){ 59 //修改地址栏中的url 60 location.href="https://www.cnblogs.com/IrVolcano" 61 } 62 63 function fun9(){ 64 //向sessionStorage中存储数据 65 sessionStorage.setItem("keya","valueA") 66 //向localStorage中存储数据 67 localStorage.setItem("keyb","valueB") 68 } 69 function fun10(){ 70 console.log(sessionStorage.getItem("keya","valueA")) 71 console.log(localStorage.getItem("keyb","valueB")) 72 } 73 function fun11(){ 74 sessionStorage.removeItem("keya") 75 localStorage.removeItem("keyb") 76 } 77 78 </script> 79 80 </head> 81 <body> 82 <button onclick="fun9()">存储数据</button> 83 <button onclick="fun10()">读取数据</button> 84 <button onclick="fun11()">清空数据</button> 85 86 <hr> 87 <button onclick="fun8()">跳转</button> 88 89 <hr> 90 <button onclick="fun5()">上一页</button> 91 <button onclick="fun6()">下一页</button> 92 93 <a href="https://www.cnblogs.com/IrVolcano">我的博客园</a> 94 95 <hr> 96 <button onclick="fun1()">信息提示框</button> 97 <button onclick="fun2()">信息输入框</button> 98 <button onclick="fun3()">信息确认框</button> 99 <button onclick="fun4()">两秒钟后向控制台打印Hello</button> 100 </body> 101 </html>
标签:function,console,log,sessionStorage,编程,12BOM,window,API,localStorage From: https://www.cnblogs.com/IrVolcano/p/18092976