The content of this article is about how to operate BOM objects in js? The method of operating BOM objects in js has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Three core objects:
window:
[window].alert Only prompt message exists alert(message)
[window].prompt allows users to manually enter var obj=prompt(message)
[window].confirm helps users make judgments. When the user clicks OK, it returns true,
to return false
open(url) Open the specified url address
close() Close the current tab
confirm.html
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>confirm弹层</title> <script> function del(){ var flag = confirm('您确定要删除吗?'); if(flag){ alert("拜拜"); } else{ alert("我们还嫩能够继续。"); } } function toBaidu(){ open('https://www.baidu.com'); } </script></head><body> <!--删除按钮--> <!--<buttun onclick="javascript:confirm('您确定要删除吗?')">删除</buttun>--> <buttun onclick="del()">删除</buttun> <buttun onclick="toBaidu()">百度</buttun> <a href="history.html">去history页面</a> <button onclick="javascript:history.forward()">前进</button> </body> </html>
success.html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>欢迎页</title> <script> function closeThis(){ close('./success.html'); } </script></head><body> <img src="/static/imghwm/default1.png" data-src="./img/gaoyuanyuan.png" class="lazy" / alt="How to operate BOM object in js? Methods to operate BOM objects in js" > 欢迎您! <button onclick="closeThis()">关闭</button> </body> </html>
setTimeout(function(){},毫秒) 指定时间延迟操作 只操作一次 var i=setInterval(function(){},毫秒) 指定时间延迟操作 操作多次(每隔一段时间操作一次) clearInterval(i) 清空定时特效 onload 事件:等待页面上的所有元素加载完毕
timing.html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>定时函数</title> <script> function print(){ setTimeout( function(){ alert("我叫jhz"); },5000 ); } print(); </script> </head><body> <input name="btn" type="button" value="定时" onclick="print();" /> </body> </html>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>定时函数</title> <script> window.onload=function(){ //保证页面上的元素加载完毕后 var btn=document.getElementsByTagName('button'); alert(btn); // 元素中的文本 innerText alert(btn.innerText); } </script> </head><body> <button id="btn">点击获取验证码</button></body></html>
history.html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>history对象</title></head><body> <!--<button onclick="javascript:history.forward()">前进</button>--> <button onclick="javascript:history.back()">后退</button> </body> </html>
history:window
History:back() Go back ===>go(-1)
forward() forward ===> go(1)
Go (index) can move forward and back.
注 Note: The forward and backward button on the browser is the same effect.
When we access a link from a web page, we can return to the web page, and then on the web page, we can advance again to the link page we just jumped to. (Like a continuous previous step and next step)
location: window
host:主机地址+端口号 hostname:主机名 port:端口号 protocol:协议 href:发送请求到指定URL reload() 刷新当前页面 replace(url) 替换 以新的页面替换当前页面
location.html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>location</title> <script> function toBaidu(){ //get请求 location.href="http://www.baidu.com"; Math Date } </script></head><body> <button onclick="javascript:alert(location.host)">查看主机地址</button> <button onclick="javascript:alert(location.hostname)">查看主机名</button> <button onclick="javascript:alert(location.port)">查看端口</button> <button onclick="javascript:alert(location.protocol)">查看协议</button> <button onclick="javascript:alert(location.href)">查看href</button> <button onclick="toBaidu()">去百度</button> <button onclick="javascript:location.reload()">刷新</button> <!--get请求--> <button onclick="javascript:location.replace('http://www.baidu.com')">replace百度</button></body></html>
—Document Object XML
document.getXXX()
var obj=document.getElementById("id attribute value") Obtaining the element object based on the id of the page element returns a single node object
————————————All returned are node collections———— ————-
document.getElementsByName("name attribute value") obtains the element object based on the name attribute of the page element
document.getElementsByClassName("class属性值") document.getElementsByTagName("节点名称")
Javascript's built-in object function
**Math对象:** Math.ceil(number)向上取整 Math.floor(number) 向下取整 Math.round(number)四舍五入 Math.random() 生成0~1的随机数 **Date日期对象:** getDate = function() {}; // 获取当前日期(天) } getDay = function() {}; //一周中的第几天 } getMonth = function() {};// 一年中的第几月 } getFullYear = function() {};// 返回年份 4位数 } getHours = function() {}; //一天的第几个小时 } getMilliseconds = function() {}; //获取毫秒 当前分钟 } getMinutes = function() {};//分钟 当前小时 } getSeconds = function() {}; //秒 当前分钟 } getTime = function() {}; //时间 1970年1月1日 到现在的毫秒数
date. html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>date</title> <script> window.onload=function(){ var date = new Date(); alert(date.getDate());//获取当前日期(天) alert(date.getDay());//一周中的第几天 alert(date.getMonth());//一年中的第几月 0-7(cong0开始) alert(date.getFullYear());// 返回年份 4位数 alert(date.getHours());//一天的第几个小时 alert(date.getMilliseconds());//获取毫秒 当前分钟 alert(date.getMinutes ());//分钟 当前小时 alert(date.getSeconds ());//秒 当前分钟 alert(date.getTime());//时间 1970年1月1日 到现在的毫秒数 document.write("结束。"); } </script></head><body></body></html>
Related recommendations:
Content analysis of date object data in js (with case)
Writing js components What are the things that need to be paid attention to? (Method introduction)
The above is the detailed content of How to operate BOM object in js? Methods to operate BOM objects in js. For more information, please follow other related articles on the PHP Chinese website!

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor