2024/6/24小于 1 分钟
- python60
- ubuntu28
- javascript16
- html14
- element-plus13
- vue8
- docker7
- git6
- rust6
- vite6
- windows5
- security4
- android2
- finance2
- openwrt1
- seo1
- uni-app1
- tauri1
npm换源
换国内源的几个方法:
# 方法一:将npm替换为cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com/
# 方法二:配置淘宝源(推荐,这样可以不安装cnpm了)
npm config set registry https://registry.npmmirror.com/
# 方法三:安装nrm
npm install -g nrm
nrm ls
nrm use taobao
2022/6/13大约 2 分钟
| 方法 | 解释 | |
|---|---|---|
| position.coords.latitude | 坐标维度 | |
| position.coords.longitude | 坐标经度 | |
| localStorage.setItem("name", "张三") | 本地存储(超长期保存) | |
| localStorage.getItem("name") | 本地存储 | |
| localStorage.removeItem("name") | ||
| localStorage.clear() | ||
| sessionStorage.setItem("name", "张三") | 会话存储(浏览器关闭被删除) | |
| sessionStorage.getItem("name") | 会话存储 | |
| sessionStorage.removeItem("name") | ||
| sessionStorage.clear() | ||
const w = new Worker('demo.js')w.onmessage = event => consolg.log(event.data) |
后台运行js(不影响浏览性能) (后台js脚本通过 postMessage()传数据) |
|
| w.terminage() | 终止该脚本运行 |
2022年5月30日小于 1 分钟
正在上传中...
2022年5月30日小于 1 分钟
HTML BOM ———— Browser Object Model (浏览器对象模型)
| 属性或方法 | 解释 | |
|---|---|---|
| window.innerWidth | 浏览器窗口的内宽度 | |
| window.innerHeight | 浏览器窗口的内高度 | |
| window.open() | 打开新窗口 | |
| window.close() | 关闭此窗口 | |
| window.moveTo() | 移动此窗口 | |
| window.resizeTo() | 调整此窗口 | |
| window.screen.width | 显示器宽度 | |
| window.screen.height | 显示器高度 | |
| window.screen.availWidth | 显示器可用宽度 | |
| window.screen.availHeight | 显示器可用高度 | |
| window.location.href | 此页面URL | |
| window.location.hostname | 此页面主机名 | |
| window.location.pathname | 此页面URL路径 | |
| window.location.protocol | http或https | |
| window.location.port | 端口号 | |
| window.history.back() | 浏览器后退按钮 | |
| window.history.go(-2) | 浏览器后对两次 | |
| window.history.forward() | 浏览器前进按钮 | |
| window.navigator.appVersion | 浏览器版本信息 | |
| window.navigator.userAgent | 用户代理表头 | |
| window.navigator.platform | 操作系统类型 | |
| window.navigator.language | 浏览器语言 | |
| window.alert("") | 警告框 | |
| window.confirm("") | 确认框 | |
| window.prompt("","") | 输入框 |
2022年5月30日小于 1 分钟
HTML DOM ———— Document Object Model (文档对象模型)
dom方法
查找元素的方法:
| 方法 | 解释 | |
|---|---|---|
| document.getElementById(id) | 通过id来查找元素(返回元素) | |
| document.getElementsByTagName(name) | 通过标签名来查找元素(返回数组) | |
| document.getElementsByClassName(name) | 通过类名来查找元素(返回数组) |
2022年5月30日小于 1 分钟
字符串
字符串是原始值不是对象,无法拥有属性和方法,但js从逻辑上把字符串视为对象。
const a = ' Learning is always a painful process. '
const b = 'E:\\project\\blog\\' // 字符串转义
// 查看字符串长度
console.log(x.length)
// 查找字符串位置(返回首次出现的索引位置,没有返回-1)
a.indexOf('alway')
// 反向查找字符串位置(返回最后一次出现的索引位置,没有返回-1)
a.lastIndexOf('o')
// 搜索字符串(与indexOf功能一样,不过search可以使用正则,indexOf可以设置搜索起始位置)
a.search('is')
// 正则搜索字符串(返回数组,没有就返回null)
a.search(/is/g) // 默认只匹配第一项,正则加g匹配所有
// 字符串切片
const text1 = a.slice(3, 19) // 注意,包含索引3,但不包含索引19
const text2 = a.slice(-12, -8)
const text3 = a.slice(8) // 从索引8剪裁到最后
// 字符串替换
const text4 = a.replace('is', 'also is') // 默认分大小写,默认只替换第一个
const text5 = a.replace(/IS/i, 'also is') // 使用正则忽略大小写
const text6 = a.replace(/is/g, 'also is') // 全局搜索全部替换
// 大小写转换
const text7 = a.toUpperCase() // 大写
const text8 = a.toLowerCase() // 小写
// 清除两边空格
const text9 = a.trim()
// 字符串转数组
const text10 = a.split(' ') // 用空格分隔
// 字符串模板
const text11 = `one: ${a}, two: ${b}`
const text12 = `length: ${a.length + b.length}`
2022年5月27日大约 7 分钟
ECMAScript和JavaScript区别
简单的理解是这样的:
ECMAScript是标准和规范,就像某个行业规范一样。
Javascript,JScript,ActionScript等脚本语言都是基于ECMAScript标准实现的。
所以说,在JavaScript,JScript和ActionScript中声明变量,操作数组等语法完全一样,因为它们都是基于ECMAScript标准。但是在操作浏览器对象等方面又有各自独特的方法,这些都是各自语言的扩展。
JavaScript组成:
2022/5/24大约 4 分钟
什么是回调
回调是将函数作为参数传递给另一个函数
回调主要用于异步函数中,其中一个函数必须等待另一个函数执行完,比如等待网络数据加载完
const hello = function (callback) {
// 该函数执行逻辑
console.log('hello')
// 该函数执行完毕,执行回调函数
callback()
}
const worldCallback = function() {
console.log('world')
}
// 执行hello函数
hello(worldCallback)
2020年5月29日大约 6 分钟
try {
// 尝试执行逻辑代码
throw '这是一个自定义错误!'
}
catch(err) {
// 捕获错误
console.log(`捕获的错误信息:${err}`)
}
finally {
// 无论是否报错,在最后必须执行的代码
}
2020年5月29日小于 1 分钟