BOM操作写法实例
2024-09-01 11:16:58
浏览器相关信息
// 浏览器信息
navigator.userAgent // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
// 运行浏览器的操作系统平台
navigator.platform // MacIntel
浏览记录历史
// 前进
history.forward()
// 后退
history.back()
url 信息
页面跳转
// 当前页面会记入浏览记录历史
location.href = 'http://www.baidu.com'
// 当前页面不会记入浏览记录历史
location.replace('http://www.baidu.com')
页面重新加载
location.reload()
获得当前 url 的信息
// 假设当前 url 是 http://192.168.31.194:8000/jquery/index.html?a=3&c=aa#b
location.href // 完整的url
location.hostname // 192.168.31.194
location.host // 192.168.31.194:8000
location.port // 8000
location.protocol // http:
location.search // ?a=3&c=aa
location.hash // #b
location.pathname // /jquery/index.html
全局对象
信息弹出框
alert('你很帅!')
确认弹出框
var isReady = confirm('准备好来吗?')
if (isReady) {
} else {
}
输入信息弹出框
var name = prompt('请输入你的名字')
console.log(name)
打开一个新窗口
open('http://baidu.com')
// 改变某个窗口的 url
open('http://baidu.com', 'a')
open('http://youku.com', 'a') // 上面窗口的地址会从 百度 变成 优酷的
过段时间后执行
// 1 秒后执行
setTimeout(function() {
// doSth
}, 1000)
每隔一段时间执行
var i = 1
// 每隔 1 秒后执行
var runId = setInterval(function(){
console.log(i++)
if(i >= 10) {
clearInterval(runId) // 停止执行
}
}, 1000)
屏幕每次刷新时执行
一般是渲染一些 UI。
var targetEl = document.querySelector('.tar')
var res
var isStop
var runId = requestAnimationFrame(function(){
targetEl.text(res)
if(isStop) {
cancelAnimationFrame(runId)
}
})
在控制台输出信息
console.log('日志信息')
console.warn('警告信息')
console.info('普通信息')
console.error('错误信息')
console.log('1+2 = %d', 3)
var person = {name: 'Joel', gender: '男'}
console.log('名字:%s,性别:%s', person.name, person.gender)
最新文章
- pthread_cond_signal惊群现象
- i春秋手动病毒查杀
- 显示textarea内容的时候没有自动换行
- oracle 知识
- 获取 苹果UDID 序列号
- windows批处理(cmd/bat)编程详解
- Learn_Dynamic
- 【转】jquery两稳定版本比较~~
- [转载] $\mathrm{Jordan}$标准型的介绍
- Redis14--jedis实现主从模式。
- ucos调度器详解
- Netty学习笔记
- 使用SimpleXML解析xml文件数据
- BZOJ 2406: 矩阵 [上下界网络流 二分答案]
- Repeater取不到服务端控件
- 一篇文章让你成为 NIO 大师 - MyCAT通信模型
- API网关设计(一)之Token多平台身份认证方案(转载)
- 【Beta阶段】测试报告
- jQuery发布1.9正式版,最后支持IE 6/7/8
- C# windform 使用TreeGridView
热门文章
- Caused by: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, ";mil_id";)
- jq 事件冒泡总结
- javascript 不用ajax 用 iframe 子域名下做到ajax post数据
- FileZilla 无法保存密码
- jquery1.9学习笔记 之选择器(基本元素二)
- 【转】Nginx配置文件详细说明
- 网站(Tomcat)超线程宕机
- 转:MFC创建多线程实例
- Gridview中的数据导出到excel中
- nginx对比haproxy 的反向代理