Skip to content

Instantly share code, notes, and snippets.

View tiu5's full-sized avatar

tiu5 tiu5

View GitHub Profile
@tiu5
tiu5 / 防抖&节流&深拷贝.js
Created August 29, 2019 02:37
防抖&节流&深拷贝
// 防抖
const debounce = (fn, wait = 50) => {
let timer = null
return function (...args) {
clearTimeout(timer)
timer = setTimeout(() => {
fn.apply(this, args)
}, wait)
}
}
@tiu5
tiu5 / formData.html
Created August 13, 2019 06:00
利用 formData 去上传文件
<input type="file" id="flie" name="file"/>
<script>
const file = document.getElementById('flie')
file.onchange = function(e) {
const f = this.files[0]
const formData = new FormData()
formData.append("file", f)
@tiu5
tiu5 / 复制文本内容.html
Created August 7, 2019 09:30
复制文本内容
<span id="pwd_spn" class="password-span">Test</span>
<button id="cp_btn">Copy</button>
<script>
document.getElementById("cp_btn").addEventListener("click", copy_password);
function copy_password() {
var copyText = document.getElementById("pwd_spn");
var textArea = document.createElement("textarea");
textArea.value = copyText.textContent;
const fs = require('fs')
const path = './Photoshop 人物肖像全面修饰实例教程'
const replaceStr = '【doyoudo全部课程都有 微信sgyx1120】'
try {
const files = fs.readdirSync(path)
files.map(item => {
const oldPath = `${path}/${item}`
const newPath = `${path}/${item.replace(replaceStr, '')}`
fs.rename(oldPath, newPath, err => { throw err})
@tiu5
tiu5 / JS调试.md
Last active January 12, 2019 12:32
JS调试

错误信息获得三点:

  • 错误发生在哪一行
  • 什么类型的错误
  • 错误信息是什么

错误类型:

  • SyntaxError: 语法错误
  • ReferenceError: 使用了不存在的变量
@tiu5
tiu5 / download.js
Created January 8, 2019 02:04
【转】借助 HTML5 Blob 实现文本信息文件下载
var funDownload = function (content, filename) {
// 创建隐藏的可下载链接
var eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
// 字符内容转变成blob地址
var blob = new Blob([JSON.stringify(content)]);
eleLink.href = URL.createObjectURL(blob);
// 触发点击
document.body.appendChild(eleLink);
@tiu5
tiu5 / reset.css
Created January 8, 2019 01:58
移动端 rem 样式
html {
font-size: -webkit-calc(100vw/7.5);
font-size: calc(100vw/7.5);
}
@tiu5
tiu5 / ajax.js
Last active January 8, 2019 01:55
发送 get 请求利用 promise 实现
/**
* @description The method will send a Ajax request with Promise.
* @param {String} url
* @return {Promise}
*/
function get(url) {
return new Promise((resolve, reject) => {
let req = new XMLHttpRequest()