dom

作用域

//通过函数分离作用域:局部变量和全局变量 //函数内部的是局部变量,只能在函数体内访问到,外部无法访问 //函数体内声明的变量有:形式参数和var声明的变量 function f(x){ var y=2 //x和y都是局部变量 } //函数执行完毕后,函数体内的执行环境被销毁,不会将数据常驻在内存中 f(5) //无法访问 //console.log(x,y)

function f(){ z=3 //没有通过var声明的变量是全局变量 } f() //console.log(z)3

引用类型

//数据类型,根据他们在操作时的不同行为,可以划分成 //1、基本类型的数据,也叫基本数据类型 单一值的数据类型 boolen string number //2、引用类型的数据,也叫复合类型数据,不仅有值还有结构, object(object Array,null) //基本类型的数据,内容都比较固定 列如,一个值最多只需要8个字节就足够存储,因此他们在赋值时会复制“值”的副本 //而引用类型 例如对象 不仅有值还有方法 内容可能较大 如果赋值时在单独创建值的副本,,就会显著占用内存,因此他赋值的是对象的地址 //意味着 着两个变量引用了同一个地址对应的对象

//基本类型赋值 b=a(传值操作) //a 1001 78 //b 1002 78

//引用类型赋值 lily=lucy(传址操作) //lucy 1001 //lily 1001

//区别是 //基本类型赋值时,内存中有俩个值,互补影响 //引用类型赋值时,内存中 ,只有1个值,谁修改都会影响到另一个

BOM

window对象

//window是BOM顶层对象,代表浏览器打开的当前窗口 //并且是javascrtipt的代码的宿主环境,js寄生在window中执行,页面中所有的全局变量都是window的属性

//window对象除了执行js代码,还用来(脚本化)渲染(操作)当前窗口 //作为对象,提供了属性和方法,来访问窗口,现代浏览器不允许总是上来就加载弹窗 //一般在按钮点击后打开窗口 <input type ="button" value="打开新窗口" onclick="open_win()"> function open_win(){ new_win=window.ope()//打开新窗口 window.alert()//在父级显示弹窗 new_win.alert()//在新窗口显示弹窗 new_win.document.write()//在新窗口页面显示 }

<input type ="button" value="关闭新窗口" onclick="close_win()"> function close_win(){ new_win.close//关闭新窗口 }

<input type="button" value="移动新窗口" onclick="move_win()"> function move_win(){ new_win.moveTo//移动窗口 new_win.moveBy//相对当前位置移动 new_win.focus() //重新获取焦点,显示窗口 }

function reset_win(){ new_win.resizeTo()//重置固定大小 new_win.resizeBy()//相对原来增长 new_win.coresize=function(){ new_win.alert()//监听窗口大小改变 } }

onerror

//window对象的onerror方法(事件)用来监听当前页面的脚本代码错误 window.onerror=function(mag,file,line,col){ alert("来自站内的错误提示:"+msg+"\n(换行)"+"第"+line+"行,第"+col+"列") }console.log(x)

innerwidthj和innerheight

console.log(window.innerwidth,window.innerHeight)//网页尺寸

location对象

//location对象访问地址栏信息 console.log(location) //href属性---可读可写 console.log(location.href)//读取地址 //重新设置地址 -跳转 不能返回 //location.href ="http://....."

//地址参数 一般也称为查询字符串 querystr ="?foo=bar&a=1&b=2" //转化成对象 便于使用 result={foo:"bar" ,a:1,b:2} function geargs(querystr){ var result ={} //一系列计算 var pairs =querystr.slice(1)//foo=bar&a=1&b=2 //拆分成对 var pairs =str.split("&")//["foo=bar","a=1""b=2] //循环 分别提取每一对中的参数和值的部分 for (var i = 0; i < pairs.length; i++) { pairs[i]; // foo=bar var pos = pairs[i].indexOf("="); var name = pairs[i].slice(0, pos); var value = pairs[i].slice(pos+2); result[name] = value; } return result; }

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="" cid="n35" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); --select-text-bg-color: #36284e; --select-text-font-color: #fff; font-size: 0.9rem; line-height: 1.71429em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; margin-left: 2em; padding-left: 1ch; padding-right: 1ch; width: inherit; color: rgb(31, 9, 9); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> var result = getArgs(location.search);
console.log(result);</pre>

}

<input type="button" value="assign跳转" onclick="assign()">//assign(指定)(跳转) <input type="button" value="replace跳转" onclick="replace()">//replace(跳转) <input type="button" value="reload刷新" onclick="reload()">//reload(刷新) location.assign(跳转地址) location.replace(跳转地址) location.reload(刷新)

返回 返回 go(1)前进 go(0)刷新 go(-1)返回

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 什么是 BOM ? 1.浏览器对象模型 Browser Object Model 2.BOM的核心对象是windo...
    WeekOne阅读 3,118评论 0 2
  • ====DOM==================================================...
    悦动燃爆阅读 1,579评论 0 0
  • DOM 🚜 dom对象是HtmlElement类型 DOM document object model 文档对象模...
    Rikka丶阅读 2,844评论 1 0
  • _________________________________________________________...
    fastwe阅读 2,688评论 0 0
  • 第一章 1.什么是DOM DOM: Document Object Model(文档对象模型) 是JavaScri...
    fastwe阅读 4,225评论 0 0