JavaScript复习
let:局部变量
const:常量 不可变(ES6)
apply:控制this的指向
this:无法指向的,是默认的指向
内部对象
Data
var now = new Data()
now.getFullYear();
now.getMonth(); //月 0-11
now.getDate();
now.getDay();
now.getHours();
now.getMinutes();
now.getSeconds();
now.getTime(); //时间戳
new Date(151516356)//时间戳转化为时间
now.toLocaleString()
now.toGMTString()
json
- 对象用{}
- 数组用[]
- 所有的键值对都是用key:value
var user={name:"liu",sge:3,sex:"女"}
//对象转化为json字符串
var jsonUser=JSON.stringify(user)
//字符串转化为对象
var obj=JSON.parse({"name“:"liu","sge":3,"sex":"女"})
JSON 和JS的区别
var js={
name:"liu",
sge:3,
sex:"女"
}
var json='
{"name“:"liu","sge":3,"sex":"女"}
'
Ajax
- 原生的js写法,xhr异步请求
- jQuery 封装好的方法 $(’#id ').ajax()
- axios 请求
面向对象
对象调用类(对象)的方法
原生方法
xiaoming.proto = user
规范 class
calss student{
//构造方法
construstor(name){
this.name=name;
}
hello(){
alert("hello")
}
}
class pupil extends Student{
constructor(nam,grade){
super(name)
this.grade=grade;
}
myFrade(){
aleat("xiao")}
}
var xiaoming=new Studnet("xiaoming");
var xiaohong=new Studnet("xiaohong");
操作BOM对象(浏览器)
window
- window.innerHeight()
- window.outerHeight()
Navigator 不用
- navigator.appName
- navigator.platform
- navigatot.
screen
screen.windth
screen.height
location
页面的URL信息
host:“www.baidu.com”
href:“https://www.baidu.com/”
reload:f reload() //刷新网页
location.assign(‘https://blog.com’) //设置新的地址
document
document代表当前页面,HTML,DOM文档树
document.title=""
document.cookie
document.getElementById('app')
history
back()
forward()
DOM对象(文档文件)
网页就是一个DOM树形结构
- 增删改查
- 要操作想获取
document.getElementByTagName('h1')
document.getElementById('p1')
document.getElementByClassName('p2')
var father=document.fetElementByID('father')
var childrens = father.children
var id1=document.getElementById('p1')
id1.innerText='456'
id1.innerHTML='<strong>123</strong>'
id1.style.color=''
id1.style.fontColor='' //下划线转驼峰命名
删除
//根据父节点来删除子节点
father.removeChild(children)
//删除之后下标改变
//插入节点
获得了Dom节点 空的可以直接添加 innerText
list.appendChild(s)
list.insertBefore(new,ee)
//创建节点
var newP=document.createElement('p')
newP.id="newP"
newP. innerText=
//设置节点属性值
var myScript=document.getElement('script')
myScript.setSttribute('type','text/javascript')