navigator.sendBeacon(url, data)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html, body {
height: 100%;
overflow-y: auto;
}
li {
line-height: 100px;
}
</style>
</head>
<body>
<ul>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
<script>
var observer = new IntersectionObserver(changes => {
changes.forEach(item => {
if (item.isIntersecting) {
item.target.style.color = 'red'
observer.unobserve(item.target)
} else {
item.target.style.color = 'green'
}
})
})
var targetList = document.querySelectorAll('li')
targetList.forEach(target => observer.observe(target));
</script>
</body>
</html>
// data 为返回的数据流
var resBlob = data
// type 为流的格式, 可从响应头里取得,动态替换
var blob = new Blob([resBlob], {'type': 'application/xlsx'})
var downloadUrl = window.URL.createObjectURL(blob)
var a = document.createElement('a')
a.setAttribute('target', '_blank')
a.setAttribute('href', downloadUrl)
// 文件后缀一定要跟上面流的格式一一对应
a.setAttribute('download', 'report.xlsx')
a.click()
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
-webkit-overflow-scrolling : touch;
-webkit-tap-highlight-color: rgba(0,0,0,0);
document.activeElement.blur();
- video::-webkit-media-controls-enclosure { display:none!important;}
element.scrollIntoView()
<meta http-equiv="refresh" content="0; url=pages/index.html">
background: linear-gradient(to right, blue, white);
background: radial-gradient(red 5%, yellow 25%, #1E90FF 50%);
{
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
function getElementTop(element){
var actualTop = element.offsetTop;
var current = element.offsetParent;
while (current !== null){
actualTop += current.offsetTop;
current = current.offsetParent;
}
return actualTop;
}
document.elementFromPoint(x, y); // target Element
{
-webkit-user-drag: none;
-webkit-user-select: none;
-o-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none
}
document.querySelector('#copy_path').select();
document.execCommand('copy');
window.requestAnimationFrame(callback) // 有点类似setTimeout
window.cancelAnimationFrame(id) // 类似clearTimeout(id)
- 效验密码强度
^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
- 校验中文
^[\\u4e00-\\u9fa5]{0,}$
- 由数字、26个英文字母或下划线组成的字符串
^\\w+$
- 校验E-Mail 地址
^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$
- 校验身份证号码
^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$
^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$
- 校验金额
^\+?(?!0+(\.00?)?$)\d+(\.\d\d?)?$
- 校验日期
^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$
- 校验手机号
^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$
- 判断IE的版本
^.*MSIE [5-8](?:\\.[0-9]+)?(?!.*Trident\\/[5-9]\\.0).*$
- 检查URL的前缀
if (!s.match(/^[a-zA-Z]+:\\/\\//)) {
s = 'http://' + s;
}
- 提取URL链接
^(f|ht){1}(tp|tps):\\/\\/([\\w-]+\\.)+[\\w-]+(\\/[\\w- ./?%&=]*)?
- 文件路径及扩展名校验
^([a-zA-Z]\\:|\\\\)\\\\([^\\\\]+\\\\)*[^\\/:*?"<>|]+\\.txt(l)?$
- 提取颜色
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
- 提取网页图片
\\< *[img][^\\\\>]*[src] *= *[\\"\\']{0,1}([^\\"\\'\\ >]*)
- 提取页面超链接
(<a\\s*(?!.*\\brel=)[^>]*)(href="https?:\\/\\/)((?!(?:(?:www\\.)?'.implode('|(?:www\\.)?', $follow_list).'))[^"]+)"((?!.*\\brel=)[^>]*)(?:[^>]*)>
- 查找CSS属性
^\\s*[a-zA-Z\\-]+\\s*[:]{1}\\s[a-zA-Z0-9\\s.#]+[;]{1}
- 抽取注释
<!--(.*?)-->
- 匹配HTML标签
<\\/?\\w+((\\s+\\w+(\\s*=\\s*(?:".*?"|'.*?'|[\\^'">\\s]+))?)+\\s*|\\s*)\\/?>
- 匹配img标签
/<img [^>]*src=['"]([^'"]+)[^>]*>/gi
- 上传文件转base64字符串
updateFile function (event) {
return new Promise((resolve, reject) => {
let file = event.target.files[0]
let reader = new FileReader(file)
reader.readAsDataURL(file, 'utf-8')
reader.onload = function () {
let result = this.result.replace(/data:.*;base64,/i, '')
resolve(result)
}
})
}
async updateJarFile function (event) {
let jarFile = await updateFile(event)
console.log(jarFile)
}
- Linux下干掉某一进程
ps axu | grep string
kill -9 id