当前位置:网站首页>Day30 JS notes BOM and DOM 2021.09.24
Day30 JS notes BOM and DOM 2021.09.24
2022-06-28 11:30:00 【Little dream of becoming a big man】
javaScript Three major components :DOM、BOM、ECMAScript
ECMAScript: Basic grammar 、 data type 、 Variable 、 Operator ...
BOM:Browser Object Model Browser object model , Provides a set of methods for operating the browser , The object is Window;
BOM To get the size of the browser window (window Omission , The unit is px, Only read , Cannot be modified )
Method 1:( Include scroll bar )
- Height of browser window window.innerHeight
- The width of the browser window window.innerWidth
Method 2:( No scrollbars , The size of the scroll bar needs to be recalculated ,document Represents a document object ,document.documentElement Express html file )
- document.documentElement.clientWidth
- document.documentElement.clientHeight
Browser pop-up layer :alert、prompt、confirm
Browser address bar Method :
- window.location.href = ' Jump to address ' Opening the current page will automatically jump to the new address
- window.location.reload(true) Parameters can be chosen The current page is always loaded ( Don't write in the overall situation )
- window.location.search Find the carrying parameters in the address bar

Browser history Method :( There must be a click to jump operation )
- history.back() function -- One page back
- history.forward() function -- One page ahead
- history.go( The number ) function -- Forward or backward specified number of pages ( Negative numbers go back , Forward in positive numbers )
Browser version information Method :
window.navigator Record some information about the browser
Browser Events Method :
1.load Express loading , When all the contents in the page are loaded, execute ( It is suggested to write at the bottom of the page , The code is executed in sequence )
2.scroll This event will be triggered when the browser scroll bar scrolls ( common )
3.resize This event will be triggered when the browser window changes
- In the label , Think of events as attributes of tags οnclick=" function ()"
- binding id id. event = function(){}
- window.onXXX( Event name ) = function(){}

The distance between the scroll bar and the browser :( There's a compatibility problem )
- Distance from top document.documentElement.scrollTop
- Distance from left side document.documentElement.scrollLeft

Compatible writing :
- document.documentElement.scrollTop || document.body.scrollTop
- document.documentElement.scrollLeft || document.body.scrollLeft
Screen size screen
- window.screen.width/height Width height initial small
- screen.availWidth/Height Usable Visual range
Timer :window.setInterval(function(){ Code snippet to execute }, Number of milliseconds )
- After the timer runs, it can be cleared manually clearInterval( The name of the timer / Return value of timer )
Time delayer :setTimeout( function , Number of milliseconds )
- Clear the delayer clearTimeout()
DOM:( be based on document)document object model Document object model
Common acquisition dom Structural approach : document. Method
- According to... In the label id Property acquisition document.getElementById('id Name ')
- Get... According to the class name in the tag document.getElementsByClassName('class Name ')
- Get... According to the tag name document.getElementsByTagName(' The tag name ')
- according to name Property acquisition document.getElementsByName('name Name ')
A simple and easy way to get (css Selector mode )
- document.querySelector('css Selectors ') Get the first one that meets the condition
- document.querySelectorAll('css Selectors ') Get all that meet the conditions

dom Attribute operation :
- increase : dom Elements .setAttribute(' Property name ',' Property value ')
- Delete : dom Elements .removeAtttribute(' Property name ')
- Change : dom Elements .setAttribute(' Property name ',' Property value ')
- check : dom Elements .getAttribute(' Property name ')

dom Get content :
1.dom Elements .innerHTML = ' Imported values ' ( Get the text in the structure , Text can be set , Resolvable tags )
2.dom Elements .innerText ( Get the text in the structure , Text can be set , Unresolved tags )
3.dom Elements .outerHTML ( You can get the text in the structure but have labels , Text can be set , Resolvable tags )

Operation of class name : adopt js Add a class name to the tag
- dom Elements .className = ' Class name ' add to
- dom Elements .className = ' ' Delete
Element style operation : adopt js Add attributes and attribute values to elements
- If css Attribute only has one English word , With the help of the acquisition method of the object :dom Elements .style.css attribute = 'css Property value '
- If css Attribute has more than one English word :
- dom Elements .style.css Attribute hump naming = 'css Property value '
- dom Elements .style['css attribute '] = 'css Property value '

Operation of form elements :
- Get the values in the form dom Elements .value
边栏推荐
猜你喜欢

阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别

js中的class类模式及语法 2021.11.10

TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush

day29 js笔记 2021.09.23

人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了

Jetpack Compose Desktop 桌面版本的打包和发布应用

Recommended practice sharing of Zhilian recruitment based on Nebula graph

Redis6 一:Nosql引入、Redis可以解决什么问题?

零基础自学SQL课程 | IF函数

无法重新声明块范围变量
随机推荐
day39 原型链及页面烟花效果 2021.10.13
选择哪种编程语言,会吸引优秀的人才?
动态库(共享库)的制作和使用
行业分析| 快对讲,楼宇对讲
Day23 JS notes 2021.09.14
JS foundation 5
day33 js笔记 事件(下)2021.09.28
Create ECS using API shortcut
100 important knowledge points that SQL must master: retrieving data
一套十万级TPS的IM综合消息系统的架构实践与思考
JS基础3
Solve the problem of reading package listsdonebuilding dependency treereading state informationdone
智联招聘基于 Nebula Graph 的推荐实践分享
基于验证码识别的机器学习项目captcha_trainer操作实践
Word、PDF、TXT文件实现全文内容检索需要用什么方法?
JS foundation 2
JS基础4
Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
[no title] the virtual machine vmnet0 cannot be found and an error is reported: there is no un bridged host network adapter
Mysql安装配置以及解决重装Mysql时忘记root password问题