var 定义全局变量 let定义局部变量只可以在函数内使用 const定义常量
URL:统一资源定位符
// DOM (Document Object Model) 译为文档对象模型,是 HTML 和 XML 文档的编程接口。
//window 窗口对象, 可以用来控制当前窗口, 或打开新的窗口
//screen 有关客户端的屏幕和显示性能的信息
// window.screen 对象包含有关用户屏幕的信息。
// window.screen 对象在编写时可以不使用 window 这个前缀。
// 一些属性:
// screen.availWidth - 可用的屏幕宽度(以像素计,减去界面特性,比如窗口任务栏)
// screen.availHeight - 可用的屏幕高度
// back() 加载历史列表中的前一个 URL
// forward() 加载历史列表中的下一个 URL
// go(number) 加载历史列表中的某个具体的页面 -1 前一个页面 1 后一个页面 0刷新页面
- var back_btn = document.getElementById('backbtn');
- back_btn.onclick = function () {
- history.go(-1);
- }
- function forward() {
- history.go(1);
- }
- function flushH() {
- history.go(0);
- }
// href 返回当前页面的url
// pathname 返回url的路径名
// reload() 刷新本页面
- var href = document.getElementById("href");
-
- href.onclick = function () {
-
- window.location.href = "https://www.baidu.com";
-
- }
-
- var pathname = document.getElementById('pathname');
-
- pathname.onclick = function () {
-
- alert(location.pathname);
-
- }
-
- var reload = document.getElementById('reload')
-
- reload.onclick = function () {
-
-
- window.location.reload();
-
- }
// 浏览器代号 Mozilla
// navigator.appCodeName
// 浏览器名称 Netscape
// navigator.appName
// 浏览器版本 5.0
// navigator.appVersion
// 启用cookie操作 true
// navigator.cookieEnabled
// 硬件平台 win32
// navigator.platform
//用户代理 Mozilla/5.0...
//navigator.userAgent
// 语言环境 zh-CN
// navigator.systemLanguage
//Window对象的常用方法
// prompt 显示可提示用户输入的对话框
// alert 显示带有一个提示信息和一个确定按钮的警示框
// confirm 显示一个带有提示信息、确定和取消按钮的对话框
// close 关闭浏览器窗口(仅限open()打开的新窗口)
// open 打开一个新的浏览器窗口,加载给定 URL 所指定的文档
//(URL/打开方式/窗口参数/是否取代当前页面历史记录的布尔值)
// setTimeout 在指定的毫秒数后调用函数或计算表达式
var box1 = document.getElementById('box1');
var start = document.getElementById('start');
var stop = document.getElementById('stop');
var num = 0;
function fn() {
num++;
box1.innerHTML = num
set = setTimeout(fn, 100);
}//递归
start.onclick = function () {
fn();
}
stop.onclick = function () {
clearTimeout(set);
}
// setInterval 按照指定的周期(以毫秒计)来调用函数或表达式
// onload 一个页面或一幅图像完成加载 在对象已加载时触发
//onresize 随着窗口或框架大小的改变而改变 window.οnresize=function(){}
//onscroll 滚动条滚动事件
// 当滚动条滚动的时候,获取滚动条数据
// document.documentElement.scrollTop; //IE、FireFox..
// document.documentElement.scrollLeft; //IE、FireFox..
// document.body.scrollTop; //Chrome
// document.body.scrollLeft; //Chrome
// window.onscroll = function () {
// console.log(document.documentElement.scrollTop);
// console.log(document.body.scrollTop);
// }
// 兼容写法:
// var wtop = document.documentElement.scrollTop || document.body.scrollTop;
// window.btoa(str)
// 该方法返回一个 base - 64 编码的字符串
// window.atob(str)
完整
body
- type="button" value="back" id="backbtn">
- type="button" value="forword" id="forword" onclick="forward()">
- type="button" value="刷新" onclick="flushH()">
- type="button" value="跳转到抖音" id="href">
- type="button" value="返回网址" id="pathname">
- type="button" value="刷新本页面" id="reload">
js
- <script>
- // DOM (Document Object Model) 译为文档对象模型,是 HTML 和 XML 文档的编程接口。
- //window 窗口对象, 可以用来控制当前窗口, 或打开新的窗口
- //screen 有关客户端的屏幕和显示性能的信息
- // window.screen 对象包含有关用户屏幕的信息。
- // window.screen 对象在编写时可以不使用 window 这个前缀。
- // 一些属性:
- // screen.availWidth - 可用的屏幕宽度(以像素计,减去界面特性,比如窗口任务栏)
- // screen.availHeight - 可用的屏幕高度
-
-
- // history对象
- // back() 加载历史列表中的前一个 URL
- // forward() 加载历史列表中的下一个 URL
- // go(number) 加载历史列表中的某个具体的页面 -1 前一个页面 1 后一个页面
-
- var back_btn = document.getElementById('backbtn');
- back_btn.onclick = function () {
- history.go(-1);
- }
- function forward() {
- history.go(1);
- }
- function flushH() {
- history.go(0);
- }
- // location
- // href 返回当前页面的url
- // pathname 返回url的路径名
- // reload() 刷新本页面
- var href = document.getElementById("href");
- href.onclick = function () {
- window.location.href = "https://www.baidu.com";
- }
- var pathname = document.getElementById('pathname');
- pathname.onclick = function () {
- alert(location.pathname);
- }
- var reload = document.getElementById('reload')
- reload.onclick = function () {
-
- window.location.reload();
- }
-
- // navigator
-
- // 浏览器代号 Mozilla
- // navigator.appCodeName
-
- // 浏览器名称 Netscape
- // navigator.appName
-
- // 浏览器版本 5.0
- // navigator.appVersion
-
- // 启用cookie操作 true
- // navigator.cookieEnabled
-
- // 硬件平台 win32
- // navigator.platform
-
- //用户代理 Mozilla/5.0...
- //navigator.userAgent
-
- // 语言环境 zh-CN
- // navigator.systemLanguage
- script>