- 自定义函数
- .函数的返回值:js中可以返回任意类型,
js中每个函数都有返回类型,如果没有return则返回未定义(undefined)
- 创建函数:
普通函数:function f(){
return 0;//返回数字零
}
匿名函数: (function(){
return 0;
})();
高阶函数:可以把函数作为参数
Function fb(a,b){
return a(b);
}
箭头函数:fb=()=>{
return 0;
}
- 函数的调用
普通函数,高阶函数,箭头函数都是直接对象名调用//fb();
匿名函数在创建的同时也被调用了
- window对象
方法:方法名.要进行的操作
(1).History(浏览过的网址,相当于历史记录)//history.对象名
同一浏览器下浏览过的网址来回切换
返回:history.back//返回上一级
前进: history.forward//切换到下一级
history.go(2)或history.go(-2)//规定前进的次数或返回的次数
- .location(当前界面的网址)
location.herf()//loction.herf=”https://www.baidu.com”;//跳转到百度界面
loction.reload//刷新当前界面
- window常用对象
方法:方法名.要进行的操作
(1).window当前界面
window.open()//window.open(“https://www.baidu.com”)打开百度界面
Window.close()//window.open(“https://www.baidu.com”)关闭百度界面
(2).定时器
设置定时器:每刷新一次执行一次
setTimeout(function f(){
alert(“99”)//弹窗
},1000)//时间间隔为一秒
设置循环定时器:重复执行直到清除定时器
setInterval(function f(){
alert(“99”)//弹窗
},1000);
清除定时器
clearTimeout();
clearInterval();
四.内置对象(数学函数,日期函数)
日期函数
new Date()//中国标准时间
new Date().tolocationTimeString();//当前时间
new Date().tolocationDateString();//当前日期
数学函数
Math.abs()//绝对值
Math.floor//向下取整
Math.ceil//向上取整
Math.random//随机数取值范围[0,1);
Math.round//四舍五入
修改元素内容的方法
textContent//不识别HTML语句
innerHTML//识别HTML语句