JavaScript复习

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')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值