JS中常用方法

JS

window对象

setInterval() 定时器
clearInterval() 清除 定时器
setTimeout() 延时函数
cleartimeout() 清除延时函数

window.open() 打开网页
window.close() 关闭网页


loation 对象
用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面
location.pathname 文件所在路径
location.href 以当前页面打开新页面
location.reload(true) 重新请求服务器加载 传入false代表浏览器缓存中加载
location.assign() 新页面 会增加历史记录
location.replace() 打开页面 不会增加历史记录

history对象
包含用户(在浏览器窗口中)访问过的 URL
history.back() 后退
history.forward()前进
history.go(-2) 往后走2个

screen 对象
screen.height //屏幕高度
screen.width //屏幕宽度 
screen.availHeight //屏幕实际高度
screen.availWidth //屏幕实际宽度
document.body.clientHeight 视窗的高度
document.body.scrollHeight 网页的总高度


document对象
document.title
document.URL
document.cookies
document.body

document.write() 动态向页面写内容
innerHTML
innerText

属性
attributes
getAttribute(属性名)
setAttribute(属性名,属性值)
setAttributeNode(Attr)
removeAttribute

元素
createElement
appendChild 拼接到末尾
insertBefore(新元素,对照元素) 插入到对照元素前
replaceChild 替换元素
removeChild()

子节点
chilidNodes 所有子节点
firstChild
lastChild
previousSibling
nextSibling
nodeType

子元素
chlidren 获取所有子元素
firstElementChild
lastElementChild
previousElementSibling
nextElementSibling


element.scrollIntoView(true); 滚动条滚动到元素上边界对齐 false代表下边界
window.scrollBy(x,y); 滚动条滚动 偏移量
window.scrollTo(x,y); 滚动条滚动到 某个位置

事件
onfocus 获取焦点
onblur 失去焦点

onClick
onDblClick

onmouseover 鼠标移入
onmouseout 鼠标移出
onmousemove 鼠标移动

onmousedown
onmouseup 鼠标按下和松开

onsubmit 表单提交

onkeypress
onkeyup 按键被按下和松开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值