JavaScript学习笔记三

Window#

window对象不但充当全局作用域,而且表示浏览器窗口。

window.innerWidth//视口宽度
window.innerHeight//视口高度
window.outerWidth//浏览器宽度
window.outerHeight//浏览器高度

location#

location对象表示当前页面的URL信息

location.href; // 'http://www.example.com:8080/path/index.html?a=1&b=2#TOP'
location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'

location.assign("https://www.baidu.com/");// 要加载一个新页面
location.reload(); // 刷新页面

document#

document对象表示当前页面, 是DOM树的根节点

cookie 是一些数据, 存储于你电脑上的文本文件中
cookie 以键/值对的形式保存

  • 创建 cookie 设置过期时间、属于当前页面
    document.cookie="username=John Doe;expires=Thu, 18 Dec 2043 12:00:00 GMT; path=/";
  • 读取 cookie
    var x = document.cookie;
  • 修改 cookie
    document.cookie="username=John Smith; expires=Thu, 18 Dec 2043 12:00:00 GMT; path=/";
  • 删除 cookie 设置过期即可
    document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 GMT";

screen#

screen对象表示屏幕的信息

screen.width; // 屏幕宽度,以像素为单位;
screen.height; // 屏幕高度,以像素为单位;
screen.colorDepth; // 返回颜色位数,如8、16、24。

navigator对象表示浏览器的信息

navigator.appName; // 浏览器名称;
navigator.appVersion; // 浏览器版本;
navigator.language; // 浏览器设置的语言;
navigator.platform; // 操作系统类型;
navigator.userAgent; // 浏览器设定的User-Agent字符串。

history#

包含浏览器的历史

history.back(); // 与在浏览器点击后退按钮相同
history.forward(); // 与在浏览器中点击向前按钮相同

弹窗#

  • 警告框
    window.alert("sometext");
  • 确认框
    window.confirm("sometext");
  • 提示框
    window.prompt("sometext","defaultvalue");

计时器#

  • setInterval() 方法
    setInterval() 间隔指定的时间(毫秒),不停地执行指定的代码
    var myInterval = setInterval(function(){alert("Hello")},3000);

  • clearInterval() 方法
    要使用 clearInterval() 方法, 在创建计时方法时你必须使用全局变量
    clearInterval(clearInterval);

  • setTimeout() 方法
    间隔指定的时间,执行一次指定的代码
    var myVar = setTimeout(function(){alert("Hello")},3000);

  • clearTimeout()
    要使用clearTimeout() 方法, 你必须在创建超时方法中(setTimeout)使用全局变量:
    clearTimeout(myVar);

posted @   MarchXD  阅读(38)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示
主题色彩