当前位置:网站首页>Window object
Window object
2022-06-24 18:35:00 【Brother Mengfan】
Catalog
2、window Common methods for objects
1、window object
function myFunction1() {
console.log('hello');
}
window.myFunction1();
console.log(window);2、window Object's Common methods
2.1、alert()
alert('start');
window.alert('end')2.2、confirm()
var f = confirm(' Are you sure you want to delete ?');
console.log(f);
if (confirm(' Are you sure you want to delete ? Cannot recover after deletion !')) {
console.log(' Successfully deleted !')
}3、window Object's Common events
3.1、 Page loading

window.onload Is a page load event , When the document content ( Include images 、 Script files 、CSS Style files, etc ) This event will be triggered after the complete loading —— That is, call the handler .window.onload Is the traditional event registration method , It will only be called once , If more than one event is written in the page , Only the last load event will be executed .
window.onload = function() {
console.log(' Page loading complete !')
};3.2、 Resize window
window.onresize = function(){ }Be careful :
(1) This event is triggered whenever the window size changes in pixels .
(2) When using this event to implement a responsive layout, you can use window.innerWidth Property to get the current screen width
window.onresize = function() {
console.log(' The current window width is :' + window.innerWidth);
console.log(' The current window height is :' + window.innerHeight);
};4、 Timer method
4.1、setTimeout()
The grammar is as follows :window.setTimeout( Callback function , [ Delay execution in milliseconds ])
console.log(' Hello ');
setTimeout(function() {
console.log('hello')
}, 2000);
console.log(' Good morning everyone !');
console.log('-----------');
function fn() {
console.log(' The output of the callback function ');
}
setTimeout(fn, 2000); <button onclick="btnOnClick()"> Click on </button>
// Click the button to end the timer
var timer = null; // Handle object , Used to get timer object
function btnOnClick() {
// Delete timer object
clearTimeout(timer);
}
var index = 0;
function fn() {
console.log(index++);
timer = setTimeout(fn, 2000);
}
timer = setTimeout(fn, 2000);4.2、setInterval()
setInterval(function() {
console.log('hello');
}, 2000); // demand : When index The value of 5 when , ends .
var timer = null;
var index = 1;
timer = setInterval(function() {
if (index === 5) clearInterval(timer);
console.log(index++);
}, 1000);边栏推荐
- Get max value of a bit column - get max value of a bit column
- [golang] leetcode intermediate - jumping game & different paths
- Palindrome string (two methods)
- About whether arm's large and small end mode is related to CPU or compiler
- Eight digit
- Mcu-08 interrupt system and external interrupt application
- Five advantages and disadvantages of Bi
- Business based precipitation component = & gt; manage-table
- Easygbs video platform TCP active mode streaming exception repair
- 微服务系统设计——数据模型与系统架构设计
猜你喜欢

Creating a new MySQL user in Amazon RDS environment - creating a new MySQL user in Amazon RDS environment

Flutter dart regular regexp matches non printing characters \cl\cj\cm\ck
Millions of dollars worth of NFT were stolen in the attack, and Google issued an emergency warning to 3.2 billion users worldwide | February 21 global network security hotspot

解决执行MapReduce程序控制台没有日志信息WARN Please initialize the log4j system properly

Recommend a distributed JVM monitoring tool, which is very practical!

Complete Guide to web application penetration testing
An analysis of the comments on the TV series Douban by procedural apes

It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements

Seven strategies for successfully integrating digital transformation
congratulate! The first dragon lizard community annual outstanding contribution award is announced. Check it now
随机推荐
Restcloud ETL extracting dynamic library table data
Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed
Three indicators to help you measure the effectiveness of digital transformation
What is decision intelligence?
Digital trend analysis of B2B e-commerce market mode and trading capacity in electronic components industry
EasyPlayer流媒体播放器播放HLS视频,起播速度慢的技术优化
Digital transformation informatization data planning and technology planning
Can the money invested in financial products be withdrawn at any time?
Creating a new MySQL user in Amazon RDS environment - creating a new MySQL user in Amazon RDS environment
congratulate! The first dragon lizard community annual outstanding contribution award is announced. Check it now
中电投先融期货这家公司怎么样?期货开户办理安全吗?
Online sequence flow chart making tool
布隆过滤器综述文章论文阅读:Optimizing Bloom Filter: Challenges, Solutions, and Comparisons
Top ten popular codeless testing tools
Skills of writing test cases efficiently
717.1-bit and 2-bit characters [sliding window]
On software requirement analysis
Redis learning -- list of redis operations
110. balanced binary tree
Nine practical guidelines for improving responsive design testing