弹窗
window.alert( 1 ) 弹窗
window.confirm( “msg”) 包含确定和取消弹窗
功能:显示一个带有指定消息和包含确定和取消按钮的对话框。点击确定返回true,取消返回false;
var value = window.confirm("去不去")console.log(value) // true / false
window.prompt(“text”,”defaultText”) 输入型弹窗
参数说明text:在对话框中显示的文本defaultText:默认输入文本返回值:点取消按钮,返回null点确定按钮,返回输入的文本
var temp = window.prompt("请输入","hello world")console.log(temp);
定时器
setTimeout 超时调用
特点:间歇一段时间,只会触发一次
setTimeout(function(){console.log("hello");},2000)
//使用递归 让超时调用实现间歇调用function show(){setTimeout(function(){console.log(1);show();},1000)}show()
setInterval 间歇调用
特点:每间隔一段时间就会触发
setInterval(function(){console.log("world");},2000)
清除定时器
<button id="btn">停止定时器</button><script>var btn = document.getElementById("btn")var timer = setInterval(function(){console.log(2);},1000)btn.onclick = function(){clearInterval(timer)}</script>
location
Window Location 主机名
window.location.hostname 属性返回(当前页面的)因特网主机的名称。
显示主机的名称:document.getElementById("demo").innerHTML = "页面主机名是 " + window.location.hostname;结果是:页面主机名是 www.w3school.com.cn
Window Location 路径名
window.location.pathname 属性返回当前页面的路径名。
显示当前 URL 的路径名:document.getElementById("demo").innerHTML = "页面路径是 " + window.location.pathname;结果是:页面路径是 /js/js_window_location.asp
history
Window History Back
history.back() 方法加载历史列表中前一个 URL。这等同于在浏览器中点击后退按钮。
<html><head><script>function goBack() {window.history.back()}</script></head><body><input type="button" value="Back" onclick="goBack()"></body></html>
Window Histore Forword
history forward() 方法加载历史列表中下一个 URL。这等同于在浏览器中点击前进按钮。
<html><head><script>function goForward() {window.history.forward()}</script></head><body><input type="button" value="Forward" onclick="goForward()"></body></html>
screen
Window Screen 宽度、高度
screen.width 属性返回以像素计的访问者屏幕宽度。
screen.height 属性返回以像素计的访问者屏幕的高度。
显示以像素计的屏幕宽、高度:document.getElementById("demo").innerHTML = "Screen Width: " + screen.width;document.getElementById("demo").innerHTML = "Screen Height: " + screen.height;结果将是:Screen Width: 1536Screen Height: 864
可用宽度、高度
screen.availWidth 属性返回访问者屏幕的宽度,以像素计,减去诸如窗口工具条之类的界面特征。
screen.availHeight 属性返回访问者屏幕的高度,以像素计,减去诸如窗口工具条之类的界面特征。
显示以像素计的屏幕可用宽度:document.getElementById("demo").innerHTML = "Available Screen Width: " + screen.availWidth;结果将是:Available Screen Width: 1536显示以像素计的屏幕可用高度:document.getElementById("demo").innerHTML = "Available Screen Height: " + screen.availHeight;结果将是:Available Screen Height: 864
