介绍
注释&输入输出
变量和常量
原始数据类型
typeof方法
运算符
数组&函数
小结
DOM
介绍
Element
Attribute&Text
小结
事件
面向对象
<script>
// 了解 定义Person类
class Person{
constructor(name,age){
this.name = name;
this.age = age;
}
show(){
document.write(this.name +","+ this.age +"<br>");
}
eat(){
document.write("吃饭。。。");
}
}
let p = new Person("小四",25);
p.show();
p.eat();
</script> // 定义Person类
let person = {
name : "小五",
age : 24,
hobby : ["游泳","跑步"],
eat : function(){
document.write("干饭..");
},
show: function(){
document.write(person.name +","+ person.age +","+ person.hobby[0]);
}
}
person.show(); class Person{
constructor(name,age){
this.name = name;
this.age = age;
}
show(){
document.write(this.name +","+ this.age +"<br>");
}
eat(){
document.write("吃饭。。。");
}
}
class student extends Person{
constructor(name,age,cls){
super(name,age);
this.cls = cls;
}
show(){
document.write(this.name+","+this.cls+","+this.age);
}
}
let s = new student("小四",18,"小班");
s.show();
//子类可以调用父类方法
s.eat(); 内置对象
Number&Math
<script>
console.log(Number.parseFloat("3.15"))
3.15
//从数字开始转换,直到不是数字为止
console.log(Number.parseInt("121a3ab"));
121
</script> Date&String
<script> let date1 = new Date(); console.log(date1); //Sat Jul 31 2021 15:21:08 GMT+0800 (中国标准时间) let date = new Date(2008,08,08,20,08,08,888); console.log(date); //Mon Sep 08 2008 20:08:08 GMT+0800 (中国标准时间) console.log(date.getFullYear()); console.log(date.getMonth()); console.log(date.getDay()); </script>
<script>
let str = new String("中国加油。");
console.log(str);
let str1 = "中国加油";
console.log(str1);
console.log(str.substr(1,3));
//国加油
console.log(str.substring(1,3));
//国加
console.log(str1.charAt(1));
//国
console.log(str.length);
//5
console.log(str.indexOf("加"));
//2
let str2 = "a,b,c,d,e";
let str3 = str2.split(",");
console.log(str3);
//["a", "b", "c", "d", "e"]
let str4 = "会不会打,笨蛋"
let str5 = str4.replace("笨蛋","**");
console.log(str5);
//会不会打,**
</script> RegExp&Array
<script>
let reg = /^[1][358][0-9]{9}$/
console.log(reg.test(15731078744));
let reg2 =/[0-9a-zA-Z_]{4,16}/
console.log(reg2.test("abc_195"));
</script> <script> let arr = [5,6,8,96,1,91] arr.push(16) console.log(arr); arr.pop() console.log(arr); arr.shift() console.log(arr); console.log(arr.includes(8)); console.log(arr.sort().reverse()); </script>
Set&Map
<script>
let s = new Set()
s.add("a")
s.add("b")
s.add("c")
s.add("d")
console.log(s);
console.log(s.size);
let st =s.keys()
for(let i =0;i<s.size;i++){
console.log(st.next().value);
}
s.delete("d")
console.log(s);
</script> <script>
let map = new Map()
map.set("张三",18)
map.set("李四",19)
map.set("王五",16)
console.log(map.size); //3
console.log(map.get("王五"));//16
let ms = map.entries();
for(let i =0; i<map.size;i++){
console.log(ms.next().value);
}
console.log(map.delete("王五"));
</script> JSON
<script>
let weather = {
city: "北京",
date: "2018-08-08",
wendu: "20~38",
shidu: "23"
}
let str123 = JSON.stringify(weather);
document.write(str123);
let weather2 = JSON.parse(str123)
console.log("城市:"weather2.city);
console.log(weather2.date);
</script> BOM
window 窗口对象
<script>
function fun() {
alert("干饭人,干饭魂");
}
//设置一次性定时器
// let d1 = setTimeout("fun()",3000);
// //取消一次性定时器
// clearTimeout(d1);
//设置循环定时器
let d2 = setInterval("fun()", 5000);
clearInterval(d2);
window.onload = function(){
let text = document.getElementById("id").innerHTML;
alert(text)
}
</script> Location 地址栏对象
location.href = "http://baidu.com"; //跳转
<body>
注册成功,<span id="num" style="color: red;">5</span>秒之后自动跳转到首页
</body>
<script>
function time(){
let node = document.getElementById("num")
let num = node.innerText;
num--;
if(num <= 0 ){
location.href = "http://baidu.com"; //跳转
clearInterval(d1); //关闭循环定时器
}
node.innerText = num;
}
let d1 = setInterval("time()",1000);
</script> 
京公网安备 11010502036488号