<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
console.log(typeof 1) // number
console.log(typeof "1") // string
console.log(typeof true) //bool
console.log(typeof NaN) // number
console.log(typeof undefined) // undefined
//
let date=new Date();
console.log(date.getFullYear()); //年
console.log(date.getMonth()) // 0-11月
console.log(date.getDate()) // 日
console.log(date.getDay()) //星期几
console.log(date.getHours()) //时
console.log(date.getMinutes()) //分
console.log(date.getSeconds()) //秒
console.log(date.getTime()); // 时间戳 1608004015942
console.log(new Date(1608004015942)) // Tue Dec 15 2020 11:49:47 GMT+0800 (中国标准时间)
console.log(date.toLocaleString()) // 2020/12/15 下午1:53:49
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
'use strict';
/**
* Json 和 对象的转换
* 对象用{}
* 数组用[]
* json本身也是字符串
*
*/
var obj={
name:"tom",
age:19
}
var json=JSON.stringify(obj)
console.log(json) // 对象--->json
var object=JSON.parse('{"name":"tom","age":19}');
console.log(object) //json--->对象
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
/**
* es 6 引入class关键字
*/
// 定义一个类: 属性+方法
class Man{
constructor(name) {
this.name=name;
}
ff(){
alert("adas")
}
}
class XiaoMing extends Man{
constructor(name,grade) {
super(name);
this.grade=grade;
}
grade(){
alert("grade")
}
}
var man=new Man("tom");
var xiaoming=new XiaoMing("xiaoming",68);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>试试~</title>
</head>
<body>
<dl id="app">
<dt>tiktok</dt>
<dt>alibaba</dt>
<dt>tencent</dt>
</dl>
<script>
/**
*dom:document 代表当前页面, html DOM文档树
*/
console.log(document.title)
var ele=document.getElementById("app") //获取文档树节点
console.log(ele)
console.log(document.cookie) //获取cookie
//如果cookie中设置了HttpOnly属性,那么通过js脚本将无法读取到cookie信息,这样能有效的防止XSS攻击
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
//bom window 代表浏览器窗口
window.alert()
console.log(window.outerHeight)
console.log(window.outerWidth);
console.log(window.innerHeight);
console.log(window.innerWidth); // 调整窗口大小试试~
console.log(window.navigator);
//bom Navicator 浏览器信息 (不建议使用)因为会被人为修改
console.log(navigator.appName)
console.log(navigator.appVersion)
console.log(navigator.userAgent)
console.log(navigator.platform)
// screen
console.log(screen.width) //1920
console.log(screen.height) //1080
// location 代表当前页面的url 信息
console.log(location.host)
console.log(location.href)
console.log(location.protocol)
// console.log(location.reload()) // 刷新页面
// console.log(location.assign("http://www.bing.com")) // 设置新的地址
// history (不建议使用)
history.back()
history.forward()
</script>
</head>
<body>
</body>
</html>