JS12

news/2025/2/12 4:07:38/

12 BOM

Broswer Object Model

12.1 常用对象

window(窗口),浏览器的窗口

var a = 1;
function test(){
    var a = 2;
    alert(a);
    alert(window.a);
}

全局变量window的属性,全局函数window的方法

浏览器body的宽度:window.innerWidth

浏览器body的宽度:window.innerHeight

open:打开新的窗口,要传入路径,打开方式,对窗口的描述

myWindow = window.open("https://www.baidu.com/?tn=57095150_2_oem_dg","_blank","");

close:关闭一个窗口

myWindow.closeWin();

moveto:移动窗口,以左上角为坐标起点

function removeWin(){
    myWindow.moveTo(200,200);
    myWindow.focus();
}

focus:使窗口获得焦点

resizeTo:改变窗口的大小

function resizeWin(){
    myWindow.resizeTo(1000,500);
    myWindow.focus();
}

screen:屏幕 也是window下面的对象,使用时可以把width省略掉

var scrWidth = window.screen.width;
var scrHeight = screen.height;
document.write("屏幕的宽"+scrWidth+"屏幕的高"+scrHeight+"<br>");
var scrAviwidth = screen.availWidth; 可用宽
var scrAviheight = screen.availHeight; 可用高(不包括任务栏)
document.write("屏幕的宽"+screen.availWidth+"屏幕的高"+screen.availHeight+"<br>");

location:地址

常用属性:href完整路径 port端口号 pathname路径名 protocol协议

用于打开新窗口

location.assign("http//www.runoob.com");

刷新:普通和强制

function reLoca(){
    location.reload();//传值为true就强制刷新
}

history:历史记录

记录当前窗口的历史,进行页面的转换

back:返回上一页

forward:进入下一页

go:进入确定的一页((-1)时为回到上一页)

12.2 弹窗

警告提示框

alert("要提示的内容");

prompt(“提示的信息”,”默认值):信息提示输入框,点击确定才返回值

var scr = prompt("请输入内容");

confirm(提示的信息)确认框  点击确定,返回true,点击取消返回false

12.3 cookie

在本地浏览器存储数据

键值对的形式

存储的数据

有效期

存储:按照cookie的格式写一个字符串,然后赋值给document.cookie,可以存多个键值对,但名字不能重复

获取:通过document.cookie就能得到之前存储的cookie是一个字符串,对字符串进行操作,得到想要的内容

清除:将存储的cookie有效期改为过去的某一天,就可以了

12.4 计时事件

setInterval(“函数”,毫秒数),每隔一定时间调用一次函数

 

clearInterval(计时器),停止一个计时器

 

setTimeout(“函数名”,毫秒数),延时器


http://www.ppmy.cn/news/536263.html

相关文章

js2c#

http://www.m2h.nl/files/js_to_c.php

CF12B Correct Solution?

题目描述 One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alices turn, she told the number nn to Bob and said: —Shuffle the digits in this num…

C1.2

任务内容 规划⼀个C类IP地址&#xff0c;例如使用子网掩码将IP地址192.168.99.0&#xff5e;192.168.99.255划分成四个子网&#xff08;可以从8位主机号中借用几位作为子网号&#xff09;&#xff0c;并使之能互联互通 解答&#xff1a;由于给的网络地址是C类地址&#xff0c…

ccy

start12345 asdfghj wwww end67890

Product of Three Numbers(CF-1294C)

Problem Description You are given one integer number n. Find three distinct integers a,b,c such that 2≤a,b,c and a⋅b⋅cn or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. …

CF1042C Array Product

原题链接&#xff1a;http://codeforces.com/contest/1042/problem/C Array Product You are given an array a a a consisting of n n n integers. You can perform the following operations with it: Choose some positions i i i and j ( 1 ≤ i , j ≤ n , i ≠ j )…

Cyc简介

Cyc中的概念被称为“常量(constants)”。常量以"#$"开头并区分大小写。常量主要分为以下几类&#xff1a; 个体&#xff0c;即individuals&#xff1a;例如 #$BillClinton 又如 #$France。 集合&#xff0c;即Collections&#xff1a;例如 #$Tree-ThePlant (包含所有…