当前位置:首页 > Web开发 > 正文

第一个参数可以是函数名/代码串

2024-03-31 Web开发

界说一个全局变量

var abc = 12 等同与 window.abc = 12

挪用一个全局函数

abc() 等同于 window.abc()

弹窗

alert() 等同于 window.alert()

confirm()

confirm() 等同于 window.confirm() //(对话弹窗) 如:<input type="button" value="删除"> var mm = document.getElementById("mm"); mm.onclick = function(){ var result = window.confirm("你确定要删除吗"); if(result) alert("删除"); else alert("打消"); }

window.prompt

window.prompt("提示文本","提示框默认文本"); 按确认时,返回值为文本框内容;按打消时,返回值为null

 

window.open

window.open("url","name","parameters") //打开一个新窗口 url:子窗口的url地点 name:给子窗口的名字 parameters:子窗口的各类参数,用逗号离隔
parameters参数: width:子窗口宽度
/ height:子窗口高度 / left:子窗口x轴坐标 / top:子窗口y轴坐标 toolbar:是否显示浏览器工具栏 / menubar:是否显示菜单栏 scrollbars:是否显示滚动条 / location:是否显示地点字段 status:是否添加状态栏

 

window.close() 

window.close() //封锁当前浏览器窗口 如:btn.onclick = function(){window.close();}

 

setTimeout

setTimeout("alert(123)",2000) //超时挪用。第一个参数可以是函数名/代码串。在2000毫秒后弹出123

clearTimeout

clearTimeout(rew) //断根超时挪用。里面的参数是函数名

 

setInterval

setInterval(wer,1000) //间歇挪用。每隔1000毫秒挪用一次wer函数

clearInterval

clearInterval(wer) //断根间歇挪用

 

location东西属性

//location 既属于window东西,也属于document东西

 

location.href //返回当前页面完整的url地点。等价于window.location.href location.pathname //返回url中的目录和(或)文件名 location.host //返回当前处事器的名称和端标语 location.hostname //返回当前处事器名称 location.host //返回当前处事器的端标语 location.hash //返回当前url地点#后面的内容,包孕#;如果没有#,则返回空字符串。 location.search //返回当前url地点?后面的内容,包孕?;如果没有?,则返回空字符串。 location.protocol //返回页面使用的协议

  location东西要领

变动url地点

setTimeout(function(){ location.href = "index2.html"; //1秒后跳转到index2页面。有历史记录 window.location = "index2.html"; //1秒后跳转到index2页面。有历史记录 //同样location.hash和location.search也可以变动url地点 location.replace("index2.html"); //1秒后跳转到index2页面。无历史纪录 },1000)

 

仿照浏览器撤退退却按钮

history.back() 或者 history.go(-1)

 

仿照浏览器前进按钮

history.forward() 或者 history.go(1) ps:history.go可以前进后撤退退却n步

 

screen东西及属性

获取网页宽高

获取网页宽高 //固定的。网页最大化,不带工具栏,,的宽高 screen.availWidth / screen.availHeight

 

获取网页的宽高

获取网页的宽高 //会跟着宽口浏览器巨细的变革而变革 window.innerWidth / window.innerHeight

 

navigator东西

userAgent属性:一个只读的字符串,声明了浏览器用于 HTTP 请求的用户代办代理头的值。

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31093.html